Repository navigation
Read positional arguments in command-line order in rfl::cli - #789
clockblocker wants to merge 1 commit into
Conversation
rfl::cli decided after parsing which short options were bool flags, so a token a flag had taken went back to the positional arguments ahead of the others: `x -v y` gave a=y, b=x. rfl::cli::read now derives an internal option table from the struct (rfl::cli::internal::make_options, options.hpp) and parses with it, so it knows while parsing what each short option does with the next token: - Positional arguments keep their command-line order: `x -v y` gives a=x, b=y. - Short<"q", std::optional<bool>> and Short<"q", DefaultVal<bool>> are flags: `-q in.txt` leaves in.txt positional. - `-o` without a value fails with "Missing value for option '-o'.", and `-v=x` on a bool short flag fails to cast x. - A root rfl::NamedTuple whose field names the processors change reads its Short and Positional fields. - "Duplicate short name" is reported before errors in the arguments. The public parse_argv and resolve_args keep working without the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5610ec0 to
0a07544
Compare
|
@clockblocker can you merge main? This should fix the test issues. (Apparently they have updated some of the runners, that's what was causing the problem.) |
|
Rebased onto |
Done, thnaks |
|
@clockblocker there appears to be a merge conflict now with your other PR. Could you address this? |
|
@liuzicheng1987 Since #790 was stacked on top of this PR, all of the changes ( Closing this PR as already included in #790 |
Summary
Builds an internal option table from the struct in
rfl::cli::readsorfl::cliknows which short options are bool flags while parsing, fixing reversed positional arguments and wrapped bool short flags.Example
main)in.txt -n out.txtfirst="out.txt",second="in.txt"(reversed)first="in.txt",second="out.txt"-q in.txt/-v in.txtCould not cast 'in.txt' to boolean ...quiet=true/verbose=true,first="in.txt"-n=xxtreated as positionalCould not cast 'x' to boolean ...-o/-o -n/-o -- xoutput=""Missing value for option '-o'.(-o=still passes"")rfl::NamedTuplewithinput_fileField named 'input_file' not found.Key details
include/rfl/cli/options.hpp(rfl::cli::internal), keeping the publicparse_argvandresolve_args<T, Ps>signatures unchanged.Shortnames in a struct are reported before argv parse errors.Short+Positionalcompile errors, and outermost-wrapper rules are unchanged.AI-authored.