diff --git a/v.v b/v.v index b99c9cfe8e..60ebbb3773 100755 --- a/v.v +++ b/v.v @@ -23,12 +23,7 @@ fn main() { //defer { println(time.ticks() - t) } // There's no `flags` module yet, so args have to be parsed manually args := compiler.env_vflags_and_os_args() - options := args.filter(it.starts_with('-')) - //NB: commands should be explicitly set by the command line (os.args) - // NOT passed through VFLAGS, otherwise the naked `v` invocation for - // the repl does not work when you have VFLAGS with -cc or -cflags set - // which may be surprising to v users. - command := if os.args.len > 1 { os.args[1] } else { '' } + options, command := compiler.get_v_options_and_main_command( args ) // external tool if command in simple_tools { compiler.launch_tool('v' + command) diff --git a/vlib/compiler/compiler_options.v b/vlib/compiler/compiler_options.v new file mode 100644 index 0000000000..51b335703f --- /dev/null +++ b/vlib/compiler/compiler_options.v @@ -0,0 +1,23 @@ +// Copyright (c) 2019 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +module compiler + +pub fn get_v_options_and_main_command(args []string) ([]string,string) { + mut options := []string + mut potential_commands := []string + for i := 0; i < args.len; i++ { + a := args[i] + if !a.starts_with('-') { + potential_commands << a + continue + }else{ + options << a + if a in ['-o', '-os', '-cc', '-cflags'] { i++ } + } + } + // potential_commands[0] is always the executable itself, so ignore it + command := if potential_commands.len > 1 { potential_commands[1] } else { '' } + return options, command +}