Repository navigation
Read positional arguments in command-line order in rfl::cli - #789
Open
clockblocker wants to merge 1 commit into
Open
clockblocker wants to merge 1 commit into
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 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.