diff --git a/vlib/flag/flag_to.v b/vlib/flag/flag_to.v index ace81bc670..dea86e1879 100644 --- a/vlib/flag/flag_to.v +++ b/vlib/flag/flag_to.v @@ -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 { diff --git a/vlib/flag/flag_to_edge_case_1_test.v b/vlib/flag/flag_to_edge_case_1_test.v new file mode 100644 index 0000000000..4ae4cf47d1 --- /dev/null +++ b/vlib/flag/flag_to_edge_case_1_test.v @@ -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 == [] +}