From b3a26ca0cee5dec8a0a163cb08ec59eb67ac979c Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 18 Feb 2021 16:42:00 +0900 Subject: [PATCH] v.pref: make passing multiple target .v files an error (#8814) --- vlib/v/pref/pref.v | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index f23593ce4c..176940cfa8 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -400,7 +400,7 @@ pub fn parse_args(args []string) (&Preferences, string) { i++ } else { - if command == 'build' && (arg.ends_with('.v') || os.exists(command)) { + if command == 'build' && is_source_file(arg) { eprintln('Use `v $arg` instead.') exit(1) } @@ -417,6 +417,9 @@ pub fn parse_args(args []string) (&Preferences, string) { if command == 'run' { break } + } else if is_source_file(command) && is_source_file(arg) { + eprintln('Too many targets. Specify just one target: .') + exit(1) } continue } @@ -440,7 +443,7 @@ pub fn parse_args(args []string) (&Preferences, string) { eprintln('Cannot save output binary in a .v file.') exit(1) } - if command.ends_with('.v') || os.exists(command) { + if is_source_file(command) { res.path = command } else if command == 'run' { res.is_run = true @@ -515,6 +518,11 @@ fn must_exist(path string) { } } +[inline] +fn is_source_file(path string) bool { + return path.ends_with('.v') || os.exists(path) +} + pub fn backend_from_string(s string) ?Backend { match s { 'c' { return .c }