cmd/v: fix run args
parent
fa4fb3b847
commit
fa5fcee584
|
@ -114,6 +114,7 @@ fn main() {
|
|||
fn parse_args(args []string) (&pref.Preferences, string) {
|
||||
mut res := &pref.Preferences{}
|
||||
mut command := ''
|
||||
mut command_pos := 0
|
||||
//for i, arg in args {
|
||||
for i := 0 ; i < args.len; i ++ {
|
||||
arg := args[i]
|
||||
|
@ -161,6 +162,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
|||
}
|
||||
if !arg.starts_with('-') && command == '' {
|
||||
command = arg
|
||||
command_pos = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +172,8 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
|||
}
|
||||
else if command == 'run' {
|
||||
res.is_run = true
|
||||
res.path = args[args.len-1]
|
||||
res.path = args[command_pos+1]
|
||||
res.run_args = args[command_pos+1..]
|
||||
}
|
||||
if res.is_verbose {
|
||||
println('setting pref.path to "$res.path"')
|
||||
|
|
|
@ -27,7 +27,6 @@ fn get_vtmp_filename(base_file_name, postfix string) string {
|
|||
}
|
||||
|
||||
pub fn compile(command string, pref &pref.Preferences) {
|
||||
mut remaining := []string
|
||||
// Construct the V object from command line arguments
|
||||
mut b := new_builder(pref)
|
||||
if pref.is_verbose {
|
||||
|
@ -72,22 +71,22 @@ pub fn compile(command string, pref &pref.Preferences) {
|
|||
println('compilation took: ' + tmark.total_duration().str() + 'ms')
|
||||
}
|
||||
if pref.is_test || pref.is_run {
|
||||
b.run_compiled_executable_and_exit(remaining)
|
||||
b.run_compiled_executable_and_exit()
|
||||
}
|
||||
// v.finalize_compilation()
|
||||
}
|
||||
|
||||
fn (b mut Builder) run_compiled_executable_and_exit(remaining []string) {
|
||||
fn (b mut Builder) run_compiled_executable_and_exit() {
|
||||
if b.pref.is_verbose {
|
||||
println('============ running $b.pref.out_name ============')
|
||||
}
|
||||
mut cmd := '"${b.pref.out_name}"'
|
||||
for i in 1 .. remaining.len {
|
||||
for arg in b.pref.run_args {
|
||||
// Determine if there are spaces in the parameters
|
||||
if remaining[i].index_byte(` `) > 0 {
|
||||
cmd += ' "' + remaining[i] + '"'
|
||||
if arg.index_byte(` `) > 0 {
|
||||
cmd += ' "' + arg + '"'
|
||||
} else {
|
||||
cmd += ' ' + remaining[i]
|
||||
cmd += ' ' + arg
|
||||
}
|
||||
}
|
||||
if b.pref.is_verbose {
|
||||
|
|
|
@ -78,6 +78,8 @@ pub mut:
|
|||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
|
||||
mod string
|
||||
run_args []string // `v run x.v 1 2 3` => `1 2 3`
|
||||
|
||||
}
|
||||
|
||||
pub fn backend_from_string(s string) ?Backend {
|
||||
|
|
Loading…
Reference in New Issue