diff --git a/cmd/v/help/default.txt b/cmd/v/help/default.txt index fea94b43de..ec9ed94674 100644 --- a/cmd/v/help/default.txt +++ b/cmd/v/help/default.txt @@ -34,7 +34,7 @@ V supports the following commands: list List all installed modules. outdated Show installed modules that need updates. * Others: - build Build a V code in the provided path (the default, so you can skip the word `build`). + build Build V code in the provided path (the default, so you can skip the word `build`). translate Translate C code to V (coming soon in 0.3). tracev Produce a tracing version of the v compiler. Use `tracev yourfile.v` when the compiler panics. diff --git a/cmd/v/v.v b/cmd/v/v.v index f4c73f1569..05bab6ad8a 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -87,7 +87,7 @@ fn main() { } else {} } - if command in ['run', 'build-module'] || command.ends_with('.v') || os.exists(command) { + if command in ['run', 'build', 'build-module'] || command.ends_with('.v') || os.exists(command) { // println('command') // println(prefs.path) builder.compile(command, prefs) diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index b2ce95bfe5..5b382995aa 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -310,6 +310,13 @@ pub fn parse_args(args []string) (&Preferences, string) { } if command.ends_with('.v') || os.exists(command) { res.path = command + } else if command == 'build' { + if command_pos + 2 != args.len { + eprintln('`v build` requires exactly one argument - either a single .v file, or a single folder/ containing several .v files') + exit(1) + } + res.path = args[command_pos + 1] + must_exist(res.path) } else if command == 'run' { res.is_run = true if command_pos + 2 > args.len { @@ -318,6 +325,7 @@ pub fn parse_args(args []string) (&Preferences, string) { } res.path = args[command_pos + 1] res.run_args = args[command_pos + 2..] + must_exist(res.path) } if command == 'build-module' { res.build_mode = .build_module @@ -327,6 +335,13 @@ pub fn parse_args(args []string) (&Preferences, string) { return res, command } +fn must_exist(path string) { + if !os.exists(path) { + eprintln('v expects that `$path` exists, but it does not') + exit(1) + } +} + pub fn backend_from_string(s string) ?Backend { match s { 'c' { return .c }