Skip to content

Find rfl::Short and rfl::Positional through other wrappers in rfl::cli - #790

Merged
liuzicheng1987 merged 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-wrapped-short-positional-main
Nov 24, 2026
Merged

liuzicheng1987 merged 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-wrapped-short-positional-main

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Finds rfl::Short and rfl::Positional through rfl::DefaultVal, std::optional, rfl::Description, rfl::Rename, and rfl::Deprecated in any nesting order in rfl::cli.

Stacked on #789 (only the top commit belongs to this PR; will rebase onto main once #789 merges).

Example

struct Config {
  rfl::Description<"Log file", rfl::Short<"l", std::optional<std::string>>> log;
  rfl::Description<"Dry run", rfl::Short<"n", bool>> dry_run;
  rfl::DefaultVal<rfl::Positional<std::string>> first = std::string("1");
  std::optional<rfl::Positional<std::string>> second;
};

// ./app -l app.log -n a.txt b.txt
// Before: Unknown short argument: -l  (and Too many positional arguments)
// After:  log="app.log", dry_run=true, first="a.txt", second="b.txt"

Key details

  • Every wrapped Short and Positional behaves identically to a bare one (flags, value options, declaration-order positionals, duplicate-short checks).
  • Combining two Short/Positional wrappers on the same field (e.g. Short<"o", Description<"...", Positional<T>>>) is now a compile-time error instead of silently ignoring the inner one.
  • rfl::Rename still applies only as the outermost wrapper.
  • Docs updated in cli.md ("Combining wrappers").

AI-authored.

@liuzicheng1987

Copy link
Copy Markdown
Collaborator

@clockblocker as far as the Windows pipelines are concerned, I am on it.

clockblocker and others added 2 commits November 22, 2026 21:18
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>
rfl::cli only recognized rfl::Short and rfl::Positional as the outermost
wrapper of a field, so `rfl::Description<"...", rfl::Short<"o", T>>` had
no `-o` and `std::optional<rfl::Positional<T>>` was not positional.

The option table now finds them through DefaultVal, std::optional,
Description, Rename and Deprecated, in any order. Every Short and
Positional counts wherever it sits: positional fields take bare arguments
in declaration order, two fields with the same short name are an error,
and a field with more than one Short or Positional does not compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clockblocker
clockblocker force-pushed the cli-wrapped-short-positional-main branch from defd21f to e8bc25a Compare November 22, 2026 20:18
@clockblocker
clockblocker marked this pull request as ready for review November 23, 2026 01:39
@liuzicheng1987

Copy link
Copy Markdown
Collaborator

@clockblocker Looks great. I am merging. Thank you for the contribution.

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.

2 participants