1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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..]
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 {
// println('args= ')
// println(args) // QTODO

View File

@ -147,7 +147,13 @@ pub fn parse_args(args []string) (&Preferences, string) {
res.only_check_syntax = true
}
'-v' {
res.is_verbose = true
// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
if args.len > 1 {
res.is_verbose = true
} else {
command = 'version'
command_pos = i
}
}
'-silent' {
res.output_mode = .silent
@ -313,21 +319,31 @@ pub fn parse_args(args []string) (&Preferences, string) {
i++
}
else {
mut should_continue := false
for flag_with_param in list_of_flags_with_param {
if '-$flag_with_param' == arg {
should_continue = true
if arg[0] == `-` {
if arg[1..] in list_of_flags_with_param {
// skip parameter
i++
break
continue
}
} else {
if command == '' {
command = arg
command_pos = i
}
}
if should_continue {
continue
}
if !arg.starts_with('-') && command == '' {
command = arg
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)
}
}
}