Skip to content

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

Open
clockblocker wants to merge 1 commit into
munich-data-engineering:mainfrom
clockblocker:cli-unknown-long-options-main
Open

clockblocker wants to merge 1 commit into
munich-data-engineering:mainfrom
clockblocker:cli-unknown-long-options-main

Conversation

@clockblocker

Copy link
Copy Markdown
Contributor

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.

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 <noreply@anthropic.com>
@clockblocker
clockblocker marked this pull request as ready for review November 25, 2026 08:45

This branch has not been deployed

No deployments
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