diff --git a/v.v b/v.v index 22cc88df6b..084db240a4 100644 --- a/v.v +++ b/v.v @@ -31,7 +31,7 @@ fn main() { } // external tool if command in simple_tools { - compiler.launch_tool('v' + command) + compiler.launch_tool('v' + command, command) return } // v run, v doc, etc @@ -50,7 +50,7 @@ fn main() { } // No args? REPL else if command == '' || (args.len == 2 && args[1] == '-') { - compiler.launch_tool('vrepl') + compiler.launch_tool('vrepl', '') return } // Construct the V object from command line arguments @@ -100,7 +100,7 @@ fn v_command(command string, args []string) { println('Translating C to V will be available in V 0.3 (January)') } 'search', 'install', 'update', 'remove' { - compiler.launch_tool('vpm') + compiler.launch_tool('vpm', command) } 'get' { println('use `v install` to install modules from vpm.vlang.io ') @@ -109,7 +109,7 @@ fn v_command(command string, args []string) { compiler.create_symlink() } 'runrepl' { - compiler.launch_tool('vrepl') + compiler.launch_tool('vrepl', 'runrepl') } 'doc' { vexe := os.executable() diff --git a/vlib/compiler/vtools.v b/vlib/compiler/vtools.v index 87a8dc0b50..2b255e3db2 100644 --- a/vlib/compiler/vtools.v +++ b/vlib/compiler/vtools.v @@ -5,11 +5,16 @@ import ( filepath ) -pub fn launch_tool(tname string) { +pub fn launch_tool(tname string, cmdname string) { is_verbose := '-verbose' in os.args || '--verbose' in os.args vexe := vexe_path() vroot := filepath.dir(vexe) set_vroot_folder( vroot ) // needed by tools to find back v + mut tname_index := os.args.index(cmdname) + if tname_index == -1 { + tname_index = os.args.len + } + mut compilation_options := os.args[1..tname_index].clone() tool_args := os.args[1..].join(' ') tool_exe := os.realpath('$vroot/tools/$tname') tool_source := os.realpath('$vroot/tools/${tname}.v') @@ -41,9 +46,9 @@ pub fn launch_tool(tname string) { } if tool_should_be_recompiled { - mut compilation_options := '' - if tname == 'vfmt' { compilation_options = '-d vfmt' } - compilation_command := '"$vexe" $compilation_options "$tool_source"' + if tname == 'vfmt' { compilation_options << ['-d', 'vfmt'] } + compilation_args := compilation_options.join(' ') + compilation_command := '"$vexe" $compilation_args "$tool_source"' if is_verbose { eprintln('Compiling $tname with: "$compilation_command"') }