flag: fix panic on single `-`

pull/6469/head
Marcin 2020-09-24 14:50:44 +02:00 committed by GitHub
parent 72ecc222ee
commit fb45e2e046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -176,7 +176,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
fs.args.delete(i)
return val
}
if arg[0] == `-` && arg[1] != `-` && arg.index_byte(shorthand) != -1 {
if arg.len > 1 && arg[0] == `-` && arg[1] != `-` && arg.index_byte(shorthand) != -1 {
// -abc is equivalent to -a -b -c
return 'true'
}

View File

@ -344,3 +344,11 @@ fn test_long_options_that_start_with_the_same_letter_as_another_short_option_bot
assert verbose == true
assert vabc == '/abc'
}
fn test_single_dash() {
mut fp := flag.new_flag_parser([
'-'
])
flag_update := fp.bool('update', `u`, false, 'Update tools')
assert flag_update == false
}