Skip to content

Read positional arguments in command-line order in rfl::cli - #22

Open
clockblocker wants to merge 1 commit into
wave-base-3from
cli-option-table
Open

clockblocker wants to merge 1 commit into
wave-base-3from
cli-option-table

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Builds an internal option table from the struct in rfl::cli::read so rfl::cli knows which short options are bool flags while parsing, fixing reversed positional arguments and wrapped bool short flags.

Example

struct Args {
  rfl::Short<"q", rfl::DefaultVal<bool>> quiet = false;
  rfl::Short<"v", std::optional<bool>> verbose;
  rfl::Short<"n", bool> dry_run;
  rfl::Short<"o", std::optional<std::string>> output;
  rfl::Positional<std::optional<std::string>> first;
  rfl::Positional<std::optional<std::string>> second;
};
Input Before (main) After
in.txt -n out.txt first="out.txt", second="in.txt" (reversed) first="in.txt", second="out.txt"
-q in.txt / -v in.txt Could not cast 'in.txt' to boolean ... quiet=true / verbose=true, first="in.txt"
-n=x x treated as positional Could not cast 'x' to boolean ...
-o / -o -n / -o -- x output="" Missing value for option '-o'. (-o= still passes "")
Root rfl::NamedTuple with input_file Field named 'input_file' not found. Reads using original NamedTuple field names

Key details

  • Adds include/rfl/cli/options.hpp (rfl::cli::internal), keeping the public parse_argv and resolve_args<T, Ps> signatures unchanged.
  • Duplicate Short names in a struct are reported before argv parse errors.
  • Long options, Short+Positional compile errors, and outermost-wrapper rules are unchanged (wrapper look-through is in Find rfl::Short and rfl::Positional through other wrappers in rfl::cli #33).

AI-authored. Base: main (after munich-data-engineering#784).

@clockblocker clockblocker changed the title Find rfl::Short and rfl::Positional through other wrappers in rfl::cli, and read positionals in command-line order Read positional arguments in command-line order in rfl::cli Nov 14, 2026
@clockblocker
clockblocker force-pushed the cli-option-table branch 2 times, most recently from cdb7e39 to 5afd3bd Compare November 17, 2026 04:18
@clockblocker
clockblocker force-pushed the wave-base-3 branch 2 times, most recently from 50295f7 to a773321 Compare November 17, 2026 07:15
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant