Skip to content

Accept abbreviated long options in rfl::cli - #27

Closed
clockblocker wants to merge 1 commit into
wave-base-7from
cli-abbreviated-long-options
Closed

clockblocker wants to merge 1 commit into
wave-base-7from
cli-abbreviated-long-options

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the opt-in rfl::cli::AllowAbbreviations processor so unambiguous prefixes of long options resolve automatically (e.g. --verb → --verbose), without changing default rfl::cli::read behavior.

Example

struct Database { std::optional<std::string> host; std::optional<int> port; };
struct Config {
  std::optional<bool> verbose;
  std::optional<bool> force_export;
  std::optional<std::string> format;
  std::optional<Database> database;
};

// Unique prefix resolves (including nested leaf names and SeparateOptionValues):
rfl::cli::read<Config, rfl::cli::AllowAbbreviations>({"--verb", "--database.h=db.local"});
// -> verbose=true, database={host="db.local"}

// Ambiguous prefix fails (with or without NoExtraFields):
rfl::cli::read<Config, rfl::cli::AllowAbbreviations>({"--for"});
// -> error: Option '--for' is ambiguous; possibilities: '--force-export', '--format'.

Key details

  • Exact matches always win over longer names with the same prefix.
  • In dotted names only the final segment abbreviates (--database.h, not --data.host); map keys, rfl::ExtraFields keys, and short options are never abbreviated.
  • Works with rfl::NoExtraFields, rfl::cli::SeparateOptionValues, and the two-step parse_argv + resolve_args API. Ignored by non-CLI formats.
  • Docs updated in cli.md ("Abbreviated long options").

Open question: keep opt-in (rfl::cli::AllowAbbreviations) or enable by default (like getopt_long/argparse)?

AI-authored. Depends on: #25.

With the new rfl::cli::AllowAbbreviations processor, a long option that
matches no field stands for the one long option it is a prefix of, so
`--rep` is `--report`. Only the last part of a dotted name is shortened
(`--database.h`, not `--data`). An exact match wins, and a prefix of
several options fails with "Option '--for' is ambiguous; possibilities:
'--force-export', '--format'." Short options, map keys and
rfl::ExtraFields keys are never abbreviated.

This is opt-in, like rfl::AllowRawPtrs. Without AllowAbbreviations,
rfl::cli::read behaves as before: a long option that is a prefix of
another is ignored, or rejected with rfl::NoExtraFields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clockblocker

Copy link
Copy Markdown
Owner Author

Branch is preserved on fork and showcase/all-lanes (d0f1fca1) as a reference artifact and parked in #117 (Moonshots & Possible Scope Creep).

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