Skip to content

Add rfl::cli::usage to generate usage and help text - #23

Open
clockblocker wants to merge 1 commit into
mainfrom
cli-usage-help-text
Open

clockblocker wants to merge 1 commit into
mainfrom
cli-usage-help-text

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Addresses munich-data-engineering/reflect-cpp#692

Problem

rfl::cli::read parses CLI flags directly from a C++ struct, but callers still have to hand-write --help output.

As structs evolve, documented flag names, short aliases, and required arguments drift out of sync with the actual parser.

enum class LogLevel { debug, info, warn };
struct Config {
  rfl::Positional<rfl::Description<"Input path", std::string>> input_file;
  rfl::Short<"p", rfl::Description<"Listen port", int>> port;
  rfl::Description<"Minimum log level", std::optional<LogLevel>> log_level;
};

const std::string help = rfl::cli::usage<Config>("app", true).value();
Usage: app <input-file> -p|--port=<value> [--log-level=<debug|info|warn>]

Arguments:
  <input-file>                   Input path. Required.
  -p, --port=<value>             Listen port. Required.
  --log-level=<debug|info|warn>  Minimum log level

Summary

  • Adds rfl::cli::usage<T>() in an isolated <rfl/cli/usage.hpp> header sharing the exact option table and processors as rfl::cli::read, so kebab-case, renames, flattened structs, and nested paths stay in sync.
  • Returns rfl::Result<std::string> (detailed = false for the usage line; true for aligned descriptions); welcomed by the maintainer on issue #692.
For Agents

@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-usage-help-text branch 2 times, most recently from 0d52e67 to 953f9db Compare November 17, 2026 05:11
@clockblocker
clockblocker force-pushed the wave-base-5 branch 2 times, most recently from 64bb06b to ca12ff5 Compare November 17, 2026 07:15
@clockblocker
clockblocker force-pushed the cli-usage-help-text branch 2 times, most recently from dc16c58 to c898597 Compare November 27, 2026 21:33
@clockblocker
clockblocker changed the base branch from wave-base-5 to main December 2, 2026 08:57
…h-data-engineering#692)

Adds `rfl::cli::usage<T, Ps...>(program_name, with_details)` in an isolated
header (`include/rfl/cli/usage.hpp`) to render command-line usage lines and
aligned argument descriptions directly from `rfl::cli`'s option table and
format-agnostic schema, matching `rfl::cli::read<T, Ps...>`.

Judge polish applied:
- Preserves cv-qualification in `add_usage_field_meta` so `const rfl::DefaultVal<T>`
  inside `rfl::NamedTuple` is accurately reported as required.
- Guards `path_separator` for root `std::map<std::string, V>` so keys render
  `--<key>=<value>` instead of `--.<key>=<value>`.
- Drops unused `<rfl/internal/processed_t.hpp>` and includes `<rfl/to_generic.hpp>`
  for standalone `<rfl/cli/usage.hpp>` builds.

Closes: munich-data-engineering#692
(Maintainer: "A PR is very welcome!")
Refs: munich-data-engineering#347
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