1
0
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:
yuyi 2023-06-25 01:35:44 +08:00 committed by GitHub
parent 3e3b289583
commit 11fa28edff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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 {
// -abc is equivalent to -a -b -c
fs.args[i] = arg.replace(shorthand.ascii_str(), '') // -abc -> -bc
return 'true'
}
}

View File

@ -410,3 +410,16 @@ fn test_empty_string_with_flag() {
mut fp := flag.new_flag_parser([''])
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 == []
}