flag: fix panic on single `-`
parent
72ecc222ee
commit
fb45e2e046
|
@ -176,7 +176,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
|
||||||
fs.args.delete(i)
|
fs.args.delete(i)
|
||||||
return val
|
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
|
// -abc is equivalent to -a -b -c
|
||||||
return 'true'
|
return 'true'
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,3 +344,11 @@ fn test_long_options_that_start_with_the_same_letter_as_another_short_option_bot
|
||||||
assert verbose == true
|
assert verbose == true
|
||||||
assert vabc == '/abc'
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue