mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
flag: fix finalize with multiple shortargs (#18544)
This commit is contained in:
parent
3e3b289583
commit
11fa28edff
@ -307,6 +307,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand u8) !string {
|
|||||||
}
|
}
|
||||||
if arg.len > 1 && arg[0] == `-` && arg[1] != `-` && arg.index_u8(shorthand) != -1 {
|
if arg.len > 1 && arg[0] == `-` && arg[1] != `-` && arg.index_u8(shorthand) != -1 {
|
||||||
// -abc is equivalent to -a -b -c
|
// -abc is equivalent to -a -b -c
|
||||||
|
fs.args[i] = arg.replace(shorthand.ascii_str(), '') // -abc -> -bc
|
||||||
return 'true'
|
return 'true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,3 +410,16 @@ fn test_empty_string_with_flag() {
|
|||||||
mut fp := flag.new_flag_parser([''])
|
mut fp := flag.new_flag_parser([''])
|
||||||
s := fp.string('something', `s`, 'default', 'Hey parse me')
|
s := fp.string('something', `s`, 'default', 'Hey parse me')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_finalize_with_multi_shortargs() {
|
||||||
|
mut fp := flag.new_flag_parser(['-ab', '-c'])
|
||||||
|
a_bool := fp.bool('a_bool', `a`, false, '')
|
||||||
|
assert a_bool
|
||||||
|
b_bool := fp.bool('b_bool', `b`, false, '')
|
||||||
|
assert b_bool
|
||||||
|
c_bool := fp.bool('c_bool', `c`, false, '')
|
||||||
|
assert c_bool
|
||||||
|
additional_args := fp.finalize()!
|
||||||
|
println(additional_args.join_lines())
|
||||||
|
assert additional_args == []
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user