pref: error if unknown argument passed to `v` (#6487)

pull/6507/head
Nick Treleaven 2020-09-29 02:13:54 +01:00 committed by GitHub
parent 9f33b33803
commit 05dcdfd267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 20 deletions

View File

@ -35,16 +35,6 @@ fn main() {
} }
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(args_and_flags)
// if prefs.is_verbose {
// println('command = "$command"')
// println(util.full_v_version(prefs.is_verbose))
// }
if args.len > 0 && (args[0] in ['version', '-V', '-version', '--version'] || (args[0] ==
'-v' && args.len == 1)) {
// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
println(util.full_v_version(prefs.is_verbose))
return
}
if prefs.is_verbose { if prefs.is_verbose {
// println('args= ') // println('args= ')
// println(args) // QTODO // println(args) // QTODO

View File

@ -147,7 +147,13 @@ pub fn parse_args(args []string) (&Preferences, string) {
res.only_check_syntax = true res.only_check_syntax = true
} }
'-v' { '-v' {
// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
if args.len > 1 {
res.is_verbose = true res.is_verbose = true
} else {
command = 'version'
command_pos = i
}
} }
'-silent' { '-silent' {
res.output_mode = .silent res.output_mode = .silent
@ -313,21 +319,31 @@ pub fn parse_args(args []string) (&Preferences, string) {
i++ i++
} }
else { else {
mut should_continue := false if arg[0] == `-` {
for flag_with_param in list_of_flags_with_param { if arg[1..] in list_of_flags_with_param {
if '-$flag_with_param' == arg { // skip parameter
should_continue = true
i++ i++
break
}
}
if should_continue {
continue continue
} }
if !arg.starts_with('-') && command == '' { } else {
if command == '' {
command = arg command = arg
command_pos = i command_pos = i
} }
continue
}
if arg in ['-V', '-version', '--version'] {
command = 'version'
command_pos = i
continue
}
if command !in ['', 'run', 'build', 'build-module'] {
// arguments for e.g. fmt are checked elsewhere
continue
}
eprint('Unknown argument `$arg`')
eprintln(if command.len == 0 {''} else {' for command `$command`'})
exit(1)
} }
} }
} }