Skip to content

Accept --key value for long options that take a value - #25

Open
clockblocker wants to merge 1 commit into
wave-base-5from
cli-key-space-value
Open

clockblocker wants to merge 1 commit into
wave-base-5from
cli-key-space-value

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the opt-in rfl::cli::SeparateOptionValues processor so long options can take their value from the next argument (--sql "SELECT 1"), without changing default rfl::cli::read behavior.

Example

struct Config {
  std::optional<std::string> name;
  std::optional<bool> verbose;
  rfl::Positional<std::optional<std::string>> input;
};

rfl::cli::read<Config, rfl::cli::SeparateOptionValues>(argc, argv);
Input Default (main) With SeparateOptionValues
--name in.txt name="", input="in.txt" name="in.txt", input=nullopt
--name --verbose name="", verbose=true Missing value for option '--name'.
in.txt --name name="", input="in.txt" Missing value for option '--name'.
--offset -5 offset="", input="-5" offset=-5

Key details

  • Next token is taken as the value unless it looks like an option (- not followed by a digit or .). --name= still passes "".
  • Bool flags, variants, rfl::Generic, and unknown options never consume the next token (--verbose 0 leaves 0 positional).
  • Works through nested structs, string maps (--labels.env prod), and wrappers. Public parse_argv is unchanged.
  • Docs updated in cli.md ("Long options").

Open question: keep SeparateOptionValues opt-in (like rfl::EnumNamesOnly in munich-data-engineering#718), or make --key value the default with an opt-out processor?

AI-authored. Depends on: #22, #34.

@clockblocker
clockblocker changed the base branch from wave-base-4 to wave-base-5 November 14, 2026 13:01
@clockblocker
clockblocker force-pushed the cli-key-space-value branch 2 times, most recently from 1746917 to 87a9246 Compare November 17, 2026 04:18
@clockblocker
clockblocker force-pushed the wave-base-5 branch 2 times, most recently from 576b6a2 to 64bb06b Compare November 17, 2026 05:11
@clockblocker
clockblocker force-pushed the cli-key-space-value branch 2 times, most recently from 2952591 to d953832 Compare November 17, 2026 07:15
With the new processor rfl::cli::SeparateOptionValues, rfl::cli::read
takes the value of a long option from the next token when it is given
without '=': `--sql "SELECT 1"`. The next token is taken unless it looks
like an option; if there is none, parsing fails with "Missing value for
option '--sql'.". Bool flags, variants, rfl::Generic and unknown options
never take the next token.

Without the processor nothing changes: a long option takes its value only
after '='. The public parse_argv, which has no option table, is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clockblocker

Copy link
Copy Markdown
Owner Author

AI-drafted: question for the maintainer on fork PR #25 ("Accept --key value for long options that take a value").

--key value is now opt-in through rfl::cli::SeparateOptionValues, so rfl::cli::read behaves exactly as on main by default. getopt_long, argparse, CLI11, Boost.Program_options and clap all take a long option's value from the next argument by default. On main, --sql "SELECT 1" sets sql to an empty string and makes SELECT 1 a positional argument without an error.

Making it the default would change three inputs that parse on main (with name a std::optional<std::string>):

Input Main With the processor
--name in.txt name="", in.txt positional name="in.txt"
--name --verbose name="", verbose=true Missing value for option '--name'.
in.txt --name name="" Missing value for option '--name'.

Would you like SeparateOptionValues to become the default (with an opt-out processor for main's behaviour), or should it stay opt-in, as rfl::EnumNamesOnly did for out-of-range enums in #718?

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