watch flag breaks backend option
Describe the bug
Without watch flag, compilation to js backend works.
With watch flag, it gives an error:
Unknown argument -baend``
Reproduction Steps
Given this single-file program:
fn main() {
println('Hello world')
}
Compile it with:
v watch -backend js_browser file.v
Expected Behavior
Program is compiled and watch starts.
Current Behavior
Error: Unknown argument -baend``
Possible Solution
So there is some args parsing issue when using watch option.
Additional Information/Context
When omitting the watch option, the above command starts working correctly.
Also, replacing -backend with -b in the above command makes the compilation work.
But -b doesn't set the correct backend (probably another bug). It works correctly for -b js, but when used with -b js_browser it sets backend to js(not js_browser).
V version
0.4.10 22c327f
Environment details (OS name and version, etc.)
Mac OS Sonoma 14.3.1
Connected to Huly®: V_0.6-22936
According to the documentation, all options should be placed in the beginning:
$ v help
V is a tool for managing V source code.
Usage:
v [options] [command] [arguments]
This works:
v -backend js_browser watch file.v
According to the documentation, all options should be placed in the beginning:
$ v help V is a tool for managing V source code.
Usage: v [options] [command] [arguments] This works:
v -backend js_browser watch file.v
Works, thanks. Closing the issue.
It should stay open until we have a better error message.
The problem is that watch needs a parameter to tell it what to watch. It is taking the -backend option as that parameter.
The 2nd problem is that it is also doing something weird with that parameter, since it prints it back out with the ck missing from -backend. Then it reports that as an unknown option.
Very strange...
It's confusing, but it's not really a bug. Simply execute the following command:
$ v watch -help
v watch 0.0.2
-----------------------------------------------
Usage: v watch [options] [--silent] [--clear] [--ignore .db] [--add /path/to/a/file.v] [run] program.v
Description: Collect all .v files needed for a compilation, then re-run the compilation when any of the source changes.
Options:
--vwatchworker Internal flag. Used to distinguish vwatch manager and worker processes.
-s, --silent Be more silent; do not print the watch timestamp before each re-run.
-c, --clear Clears the terminal before each re-run.
-k, --keep Keep the program running. Restart it automatically, if it exits by itself. Useful for gg/ui apps.
-a, --add <string> Add more files to be watched. Useful with `v watch --add=/tmp/feature.v run cmd/v /tmp/feature.v`, if you change *both* the compiler, and the feature.v file.
-i, --ignore <string> Ignore files having these extensions. Useful with `v watch --ignore=.db run server.v`, if your server writes to an sqlite.db file in the same folder.
-o, --only-watch <string>
Watch only files matching these globe patterns. Example for a markdown renderer project: `v watch --only-watch=*.v,*.md run .`
-h, --help Show this help screen.
--before <string> A command to execute *before* each re-run.
--after <string> A command to execute *after* each re-run.
The watch utility recognizes the options c and k, but not the rest of the letters (baend) :P
This is the correct usage:
v [v-options] watch [watch-options] file.v
For example:
v -backend js_browser watch -ck file.v
It is a bug, in that it the message given didn't make any sense. Useless error messages are almost worse than none at all.