Skip to content

Accept grouped short options such as -qfcsv in rfl::cli - #798

Merged
liuzicheng1987 merged 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-grouped-short-options-main
Nov 27, 2026
Merged

liuzicheng1987 merged 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-grouped-short-options-main

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds POSIX-style grouped short options (such as -qv, -fcsv, -qf csv) to rfl::cli::read. Purely additive — no input that parses on main changes meaning.

Example

struct Config {
  rfl::DefaultVal<rfl::Short<"q", bool>> quiet = false;
  rfl::DefaultVal<rfl::Short<"v", bool>> verbose = false;
  rfl::Short<"f", std::optional<std::string>> format;
  rfl::Short<"p", std::optional<int>> priority;
};
Input Result
-qv quiet=true, verbose=true
-fcsv / -qfcsv / -qf csv format="csv" (and quiet=true)
-qv false quiet=true, verbose=false
-p-42 / -p -42 priority=-42 (-42 alone stays positional)
-vq=false Option '-q' does not take a value in '-vq=false'. Write '-q=false' on its own.
-qxf Unknown short argument: -x (in '-qxf').

Key details

  • Flags consume one character each; the first value-taking option takes the rest of the token (or the next token if at the end of the group).
  • Negative numbers remain positional unless a digit short option (e.g. rfl::Short<"1", ...>) is declared.
  • Public table-less parse_argv(argc, argv) is unchanged.
  • Docs updated in cli.md ("Grouped short options").

Note on = in short option groups

In POSIX getopt, a value-taking short option treats every character after it as part of its value (-f=csv → "=csv"). On main, rfl::cli already supports = as a value separator for short options (-f=csv → "csv", -o= → "", -o=-x → "-x", -v=false → false).

To stay backwards-compatible with main and consistent between standalone and grouped forms, = remains a separator in both:

Input #798 (matches main) Strict POSIX getopt
-f=csv "csv" "=csv" (breaking change vs main)
-qf=csv quiet=true, format="csv" quiet=true, format="=csv"
-af= all=true, format="" all=true, format="="
-af==x all=true, format="=x" all=true, format="==x"

A literal value starting with = can still be passed inline as -f==x or as two tokens -f =x.

AI-authored.

rfl::cli::read now accepts several short options in one token: in
`-qvf` every flag is set up to the first option that takes a value,
which takes the rest of the token (`-qfcsv`) or, if nothing is left,
the next token (`-qf csv`). `-f=csv` keeps meaning "csv". A flag inside a
group takes no value, and an unknown letter fails with
"Unknown short argument: -x (in '-qxf').".

Inputs that parsed before keep their meaning. Grouping needs the option
table, so the public parse_argv still reads `-abc` as the short option
"abc".

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
@liuzicheng1987
liuzicheng1987 merged commit 290bdb2 into munich-data-engineering:main Nov 27, 2026
176 checks passed
@liuzicheng1987

Copy link
Copy Markdown
Collaborator

@clockblocker thank you. I am merging this one as well.

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.

2 participants