Skip to content

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

Open
clockblocker wants to merge 1 commit into
wave-base-4from
cli-wrapped-short-positional
Open

clockblocker wants to merge 1 commit into
wave-base-4from
cli-wrapped-short-positional

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

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.

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. Depends on: #22.

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 <[email protected]>
@clockblocker

Copy link
Copy Markdown
Owner Author

AI-drafted: a behaviour change in this PR, for the record.

With this PR a rfl::Positional inside another wrapper counts as a positional argument, in declaration order, exactly like a bare one. On main the outer wrapper hides it, so the field is a named option only. For

struct Args {
  rfl::Description<"Input file", rfl::Positional<std::string>> input;
  rfl::Positional<std::string> output;
};
Input main this PR main, with input a bare rfl::Positional
a.txt b.txt Too many positional arguments: expected at most 1, got 2. input=a.txt output=b.txt input=a.txt output=b.txt
--input=a.txt b.txt input=a.txt output=b.txt Conflict: positional argument and '--input' both provided. Conflict: positional argument and '--input' both provided.
b.txt Field named 'input' not found. Field named 'output' not found. Field named 'output' not found.

The only input that parsed on main and fails now is --input=a.txt b.txt, and it fails with the error main already gives when both fields are bare rfl::Positionals. Adding a Description (or Short, DefaultVal, …) no longer changes how a field is read, which is what this PR is for. (Checked by compiling the struct against main and this branch.)

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