mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
flag: add missing short flag match in flag.to_struct
, add test (#22696)
This commit is contained in:
parent
3af720921c
commit
dad8e3c766
@ -1609,6 +1609,22 @@ fn (mut fm FlagMapper) map_posix_short(flag_ctx FlagContext, field StructField)
|
||||
fm.handled_pos << pos + 1 // next
|
||||
}
|
||||
return true
|
||||
} else if !flag_ctx.next.starts_with(used_delimiter) {
|
||||
if field.short == flag_name {
|
||||
trace_println('${@FN}: found match for (${field.type_name}) ${fm.dbg_match(flag_ctx,
|
||||
field, next, '')}')
|
||||
fm.field_map_flag[field.name] = FlagData{
|
||||
raw: flag_raw
|
||||
field_name: field.name
|
||||
delimiter: used_delimiter
|
||||
name: flag_name
|
||||
arg: ?string(next)
|
||||
pos: pos
|
||||
}
|
||||
fm.handled_pos << pos
|
||||
fm.handled_pos << pos + 1 // next
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fm.config.style == .short || field.hints.has(.short_only)) && first_letter == field.short {
|
||||
|
25
vlib/flag/flag_to_edge_case_1_test.v
Normal file
25
vlib/flag/flag_to_edge_case_1_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
import flag
|
||||
|
||||
const edge_case = ['appimage', '-v', '3', '-o', '/tmp/lol.appimage', '/home/user/Projects/game/']
|
||||
|
||||
pub struct AppImageOptions {
|
||||
pub:
|
||||
verbosity int @[short: v; xdoc: 'Verbosity level 1-3']
|
||||
dump_usage bool @[long: help; short: h; xdoc: 'Show this help message and exit']
|
||||
show_version bool @[long: version; xdoc: 'Output version information and exit']
|
||||
pub mut:
|
||||
input string @[tail]
|
||||
output string @[short: o; xdoc: 'Path to output (dir/file)']
|
||||
assets []string @[short: a; xdoc: 'Asset dir(s) to include in build']
|
||||
}
|
||||
|
||||
fn test_edge_case() {
|
||||
aio, no_matches := flag.to_struct[AppImageOptions](edge_case, skip: 1)!
|
||||
assert aio.verbosity == 3
|
||||
assert aio.output == '/tmp/lol.appimage'
|
||||
assert aio.input == '/home/user/Projects/game/'
|
||||
assert aio.dump_usage == false
|
||||
assert aio.show_version == false
|
||||
assert aio.assets == []
|
||||
assert no_matches == []
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user