v.pref: prevent `Too many targets.` from triggering when the command is an external one

pull/8819/head
Delyan Angelov 2021-02-18 12:08:14 +02:00
parent ac7feb9bca
commit 0142d58aa6
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 8 additions and 7 deletions

View File

@ -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('.', '/')) mpath := os.join_path('vlib', mod_name.replace('.', '/'))
tmpname := '/tmp/${mod_name}_${os_name}.c' 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) mut b := builder.new_builder(prefs)
b.compile_c() b.compile_c()
mut res := []string{} mut res := []string{}

View File

@ -10,7 +10,7 @@ import v.util
import v.builder import v.builder
const ( const (
simple_cmd = [ external_tools = [
'fmt', 'fmt',
'up', 'up',
'vet', 'vet',
@ -63,14 +63,14 @@ fn main() {
} else { } else {
mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone() mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone()
args_and_flags << ['run', '-'] 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..]) util.launch_tool(false, 'vrepl', os.args[1..])
return return
} }
args_and_flags := util.join_env_vflags_and_os_args()[1..] 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 { if prefs.is_verbose {
// println('args= ') // println('args= ')
// println(args) // QTODO // println(args) // QTODO
@ -95,7 +95,7 @@ fn main() {
} }
// Start calling the correct functions/external tools // Start calling the correct functions/external tools
// Note for future contributors: Please add new subcommands in the `match` block below. // 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 // External tools
util.launch_tool(prefs.is_verbose, 'v' + command, os.args[1..]) util.launch_tool(prefs.is_verbose, 'v' + command, os.args[1..])
return return

View File

@ -145,7 +145,7 @@ pub mut:
cache_manager vcache.CacheManager 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{} mut res := &Preferences{}
$if x64 { $if x64 {
res.m64 = true // follow V model by default res.m64 = true // follow V model by default
@ -417,7 +417,8 @@ pub fn parse_args(args []string) (&Preferences, string) {
if command == 'run' { if command == 'run' {
break 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: <target.v|target_directory>.') eprintln('Too many targets. Specify just one target: <target.v|target_directory>.')
exit(1) exit(1)
} }