Skip to content

Report unknown long options by name under rfl::NoExtraFields in rfl::cli - #34

Open
clockblocker wants to merge 1 commit into
wave-base-4from
cli-unknown-long-options
Open

clockblocker wants to merge 1 commit into
wave-base-4from
cli-unknown-long-options

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Under rfl::NoExtraFields, rfl::cli::read rejects unknown long options by name (Unknown option '--...') instead of misreporting them as unused values or extra positional arguments.

Example

struct Database { std::string host; int port; };
struct Config {
  std::string sql;
  std::optional<Database> database;
  std::map<std::string, Database> servers;
  rfl::Positional<std::optional<std::string>> input;
};
Input (with rfl::NoExtraFields) Before (main) After
--nope=1 Value named 'nope' not used. Unknown option '--nope'.
--nope 1 in.txt Too many positional arguments: expected at most 1, got 2. Unknown option '--nope'.
--database.nope 1 Too many positional arguments: expected at most 0, got 1. Unknown option '--database.nope'.
--servers.eu.nope=1 Found 2 errors: ... Unknown option '--servers.eu.nope'.

Key details

  • Walks nested structs, string maps, and rfl::ExtraFields into the option table only when rfl::NoExtraFields is active (no behavior change without it).
  • Map keys and rfl::ExtraFields keys stay open (--labels.env=prod), while fields of structs inside maps are checked (--servers.eu.nope=1).
  • Recursive structs are guarded against infinite template recursion.
  • Docs updated in cli.md ("Unknown options").

AI-authored. Depends on: #22.

@clockblocker
clockblocker force-pushed the cli-unknown-long-options branch from c8d63f6 to 3528357 Compare November 16, 2026 05:18
@clockblocker
clockblocker force-pushed the cli-unknown-long-options branch 2 times, most recently from f7ed9ab to 737860c Compare November 17, 2026 05:11
@clockblocker
clockblocker force-pushed the wave-base-4 branch 2 times, most recently from 773baae to da208f8 Compare November 17, 2026 07:15
@clockblocker
clockblocker force-pushed the cli-unknown-long-options branch from 737860c to 944f187 Compare November 17, 2026 07:15
With rfl::NoExtraFields, `--nope=1` failed with "Value named 'nope' not
used." and `--nope 1` with "Too many positional arguments: ...". The
option table now lists every long option, through nested structs, maps
and rfl::ExtraFields, so parse_argv rejects both with "Unknown option
'--nope'.". Keys of maps and rfl::ExtraFields stay open; the fields of a
struct inside a map are known (`--servers.eu.nope` is unknown).

Without rfl::NoExtraFields, unknown long options are still ignored.

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