Skip to content

Add rfl::ImplicitValue for options whose value may be left out - #29

Closed
clockblocker wants to merge 1 commit into
wave-base-9from
implicit-value
Closed

clockblocker wants to merge 1 commit into
wave-base-9from
implicit-value

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds rfl::ImplicitValue<T, "text"> for CLI options whose value may be omitted (e.g. --color vs --color=always, --help vs --help=topic).

Example

struct Config {
  rfl::Short<"h", rfl::ImplicitValue<std::optional<std::string>>> help;
  rfl::ImplicitValue<std::optional<std::string>, "all"> help_reports;
  rfl::ImplicitValue<rfl::DefaultVal<int>, "2"> verbosity = 0;
  rfl::Positional<std::optional<std::string>> input;
};

// --help-reports in.txt  -> help_reports="all", input="in.txt"
// --help-reports=memory  -> help_reports="memory"
// --verbosity            -> verbosity=2   (absent -> 0)
// -h / -htag             -> help="" / help="tag"
// usage: --help-reports[=<value>]  ... Without a value: all.

Key details

  • A bare option uses "text"; an explicit value must follow = or attach to a short option (-htag). It never consumes the next token, even with rfl::cli::SeparateOptionValues.
  • Works across all formats via ReflectionType (JSON/generic/etc. read/write T transparently, is_empty and DefaultVal look through it, and JSON Schema unwraps to T's schema).
  • Composes in any order with Short, Description, DefaultVal, std::optional, Rename, Deprecated, grouped shorts, repeated lists, and AllowAbbreviations.
  • Compile-time errors for duplicate ImplicitValue, Positional + ImplicitValue, wrapping a struct/map, or empty "" on types where "" is invalid (enums, rfl::Literal, validated strings, fixed-size lists, etc.).
  • Docs updated in cli.md, default_val.md, and README.md.

Open questions:

  1. Template argument order: <T, "text"> (lets "text" default to "") vs <"text", T> (matches Short/Rename/Description)?
  2. Namespace: rfl::ImplicitValue (next to Short/Positional) vs rfl::cli::ImplicitValue?

AI-authored. Depends on: #21, #24, #25, #26, #27, #36.

@clockblocker
clockblocker changed the base branch from wave-base-6 to wave-base-9 November 14, 2026 13:01
@clockblocker
clockblocker force-pushed the wave-base-9 branch 2 times, most recently from 2e02bc2 to ebe2135 Compare November 16, 2026 05:18
@clockblocker
clockblocker force-pushed the implicit-value branch 2 times, most recently from a7555cd to 869157b Compare November 17, 2026 05:11
@clockblocker
clockblocker force-pushed the implicit-value branch 2 times, most recently from 3e460c0 to fe1fc5a Compare November 17, 2026 07:15
rfl::ImplicitValue<T, "text"> marks a field whose command-line option
may be given without a value: a bare `--help` or `-h` stands for the
text (empty by default), a value only follows '=' or is attached to a
short option (`-htag`), and the next token is never taken.

Like rfl::Description, it has a ReflectionType, so every other reader
and writer reads and writes its inner type; the schema shows the inner
type's schema, as for rfl::Short, and is_default_val_v looks through it.
An rfl::Rename renames the field only as the outermost wrapper. Its
constructors are noexcept only if the wrapped type's are, as for
rfl::DefaultVal.

rfl::cli finds it through the other wrappers, applies it in grouped
short options, repeated lists and abbreviations, and rfl::cli::usage
shows it as `--help[=<value>]` with "Without a value: <text>.". It needs
the option table that rfl::cli::read parses with: the public parse_argv
and resolve_args<T> do not apply it.

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

Copy link
Copy Markdown
Owner Author

Retiring top-level rfl::ImplicitValue PR to avoid polluting top-level rfl:: with CLI-only wrappers; superseded by Wave 4 rfl::cli::Opt RFC (branch preserved).

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