From 0142d58aa6cdbfe84f4af11cc176211b7596c604 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 18 Feb 2021 12:08:14 +0200 Subject: [PATCH] v.pref: prevent `Too many targets.` from triggering when the command is an external one --- cmd/tools/check_os_api_parity.v | 2 +- cmd/v/v.v | 8 ++++---- vlib/v/pref/pref.v | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/tools/check_os_api_parity.v b/cmd/tools/check_os_api_parity.v index 6d72156d80..9a7b38cf7f 100644 --- a/cmd/tools/check_os_api_parity.v +++ b/cmd/tools/check_os_api_parity.v @@ -95,7 +95,7 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string { } mpath := os.join_path('vlib', mod_name.replace('.', '/')) tmpname := '/tmp/${mod_name}_${os_name}.c' - prefs, _ := pref.parse_args(['-os', os_name, '-o', tmpname, '-shared', mpath]) + prefs, _ := pref.parse_args([], ['-os', os_name, '-o', tmpname, '-shared', mpath]) mut b := builder.new_builder(prefs) b.compile_c() mut res := []string{} diff --git a/cmd/v/v.v b/cmd/v/v.v index ef043eb9b0..d5f9459b4b 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -10,7 +10,7 @@ import v.util import v.builder const ( - simple_cmd = [ + external_tools = [ 'fmt', 'up', 'vet', @@ -63,14 +63,14 @@ fn main() { } else { mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone() args_and_flags << ['run', '-'] - pref.parse_args(args_and_flags) + pref.parse_args(external_tools, args_and_flags) } } util.launch_tool(false, 'vrepl', os.args[1..]) return } args_and_flags := util.join_env_vflags_and_os_args()[1..] - prefs, command := pref.parse_args(args_and_flags) + prefs, command := pref.parse_args(external_tools, args_and_flags) if prefs.is_verbose { // println('args= ') // println(args) // QTODO @@ -95,7 +95,7 @@ fn main() { } // Start calling the correct functions/external tools // Note for future contributors: Please add new subcommands in the `match` block below. - if command in simple_cmd { + if command in external_tools { // External tools util.launch_tool(prefs.is_verbose, 'v' + command, os.args[1..]) return diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 176940cfa8..4344ec76ca 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -145,7 +145,7 @@ pub mut: cache_manager vcache.CacheManager } -pub fn parse_args(args []string) (&Preferences, string) { +pub fn parse_args(known_external_commands []string, args []string) (&Preferences, string) { mut res := &Preferences{} $if x64 { res.m64 = true // follow V model by default @@ -417,7 +417,8 @@ pub fn parse_args(args []string) (&Preferences, string) { if command == 'run' { break } - } else if is_source_file(command) && is_source_file(arg) { + } else if is_source_file(command) && is_source_file(arg) + && command !in known_external_commands { eprintln('Too many targets. Specify just one target: .') exit(1) }