cmd/v: fix run args

pull/4274/head
Alexander Medvednikov 2020-04-07 03:21:32 +02:00
parent fa4fb3b847
commit fa5fcee584
3 changed files with 12 additions and 8 deletions

View File

@ -114,6 +114,7 @@ fn main() {
fn parse_args(args []string) (&pref.Preferences, string) { fn parse_args(args []string) (&pref.Preferences, string) {
mut res := &pref.Preferences{} mut res := &pref.Preferences{}
mut command := '' mut command := ''
mut command_pos := 0
//for i, arg in args { //for i, arg in args {
for i := 0 ; i < args.len; i ++ { for i := 0 ; i < args.len; i ++ {
arg := args[i] arg := args[i]
@ -161,6 +162,7 @@ fn parse_args(args []string) (&pref.Preferences, string) {
} }
if !arg.starts_with('-') && command == '' { if !arg.starts_with('-') && command == '' {
command = arg command = arg
command_pos = i
} }
} }
} }
@ -170,7 +172,8 @@ fn parse_args(args []string) (&pref.Preferences, string) {
} }
else if command == 'run' { else if command == 'run' {
res.is_run = true 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 { if res.is_verbose {
println('setting pref.path to "$res.path"') println('setting pref.path to "$res.path"')

View File

@ -27,7 +27,6 @@ fn get_vtmp_filename(base_file_name, postfix string) string {
} }
pub fn compile(command string, pref &pref.Preferences) { pub fn compile(command string, pref &pref.Preferences) {
mut remaining := []string
// Construct the V object from command line arguments // Construct the V object from command line arguments
mut b := new_builder(pref) mut b := new_builder(pref)
if pref.is_verbose { if pref.is_verbose {
@ -72,22 +71,22 @@ pub fn compile(command string, pref &pref.Preferences) {
println('compilation took: ' + tmark.total_duration().str() + 'ms') println('compilation took: ' + tmark.total_duration().str() + 'ms')
} }
if pref.is_test || pref.is_run { if pref.is_test || pref.is_run {
b.run_compiled_executable_and_exit(remaining) b.run_compiled_executable_and_exit()
} }
// v.finalize_compilation() // 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 { if b.pref.is_verbose {
println('============ running $b.pref.out_name ============') println('============ running $b.pref.out_name ============')
} }
mut cmd := '"${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 // Determine if there are spaces in the parameters
if remaining[i].index_byte(` `) > 0 { if arg.index_byte(` `) > 0 {
cmd += ' "' + remaining[i] + '"' cmd += ' "' + arg + '"'
} else { } else {
cmd += ' ' + remaining[i] cmd += ' ' + arg
} }
} }
if b.pref.is_verbose { if b.pref.is_verbose {

View File

@ -78,6 +78,8 @@ pub mut:
compile_defines_all []string // contains both: ['vfmt','another'] compile_defines_all []string // contains both: ['vfmt','another']
mod string mod string
run_args []string // `v run x.v 1 2 3` => `1 2 3`
} }
pub fn backend_from_string(s string) ?Backend { pub fn backend_from_string(s string) ?Backend {