Skip to content

Conversation

@leighmcculloch
Copy link

What

Add support for grouping options under the help headings in markdown output.

Why

Clap supports custom help headings for options. Options assigned a help heading will appear in the terminal output to be grouped under that help heading. For example:

$ stellar contract build -h
Build a contract from source

Usage: stellar contract build [OPTIONS]

Options:
      --manifest-path <MANIFEST_PATH>  Path to Cargo.toml
      --package <PACKAGE>              Package to build
      --profile <PROFILE>              Build with the specified profile [default: release]
      --out-dir <OUT_DIR>              Directory to copy wasm files to
  -h, --help                           Print help (see more with '--help')

Features:
      --features <FEATURES>  Build with the list of features activated, space or comma separated
      --all-features         Build with the all features activated
      --no-default-features  Build with the default feature not activated

Other:
      --print-commands-only  Print commands to build without executing them

Metadata:
      --meta <META>  Add key-value to contract meta (adds the meta to the `contractmetav0` custom section)

Options (Global):
      --global                     Use global config
      --config-dir <CONFIG_DIR>    Location of config directory, default is "."
  -f, --filter-logs <FILTER_LOGS>  Filter logs output. To turn on `stellar_cli::log::footprint=debug` or off `=off`. Can also use env var `RUST_LOG`
  -q, --quiet                      Do not write logs to stderr including `INFO`
  -v, --verbose                    Log DEBUG events
      --very-verbose               Log DEBUG and TRACE events [aliases: vv]
      --no-cache                   Do not cache your simulations and transactions [env: STELLAR_NO_CACHE=]

Today clap-markdown renders all options under a single heading, Options.

With this change clap-markdown groups options under their help headings, reflecting the same experience that clap provides on the command line.

For commands with a large number of options that make use of help headings, this significantly lowers the cognitive load of reading the help when rendered in markdown.

cc @fnando

Comment on lines +143 to +175
#[test]
fn test_empty_help_heading() {
// Test edge case where help_heading is an empty string
let app = Command::new("empty-heading-app")
.about("Test app with empty help heading")
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Enable verbose output")
.help_heading("") // Empty string
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("debug")
.short('d')
.long("debug")
.help("Enable debug output")
.help_heading("Debug Options")
.action(clap::ArgAction::SetTrue),
);

let output = help_markdown_command_custom(
&app,
&MarkdownOptions::new().show_footer(false),
);

// Should have both empty heading section and Debug Options section
assert!(output.contains("###### **:**")); // Empty heading
assert!(output.contains("###### **Debug Options:**"));
assert!(output.contains("Enable verbose output"));
assert!(output.contains("Enable debug output"));
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour with the empty case probably seems a bit odd, but it is consistent with how clap renders an empty help heading.

Copy link

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this feature and was happy to see this PR! Works great :)

leighmcculloch added a commit to stellar/stellar-cli that referenced this pull request Nov 3, 2025
### What
Move the doc-gen binary code into its own crate, separate from the
soroban-cli crate, and have it be dependent on the unmerged pull request
to clap-markdown that adds support for grouping cli options:
- ConnorGray/clap-markdown#48

### Why
The grouped options experience is a massive improvement. It makes the
help documentation easier to scan and understand. It's the way the
options are organised on the command line and the help markdown
documentation should follow suite. While the pull request adds the
feature upstream, the pull request hasn't been accepted yet.

The clap-markdown dependency isn't needed for the stellar-cli other than
doc-gen, so it is in any case good to get the dependency outside of the
soroban-cli crate, so that it isn't downloaded by cargo everytime
someone installs the stellar-cli. Moving doc-gen into its own crate is
trivial because the soroban-cli is designed to be embedded, and achieves
that. Additionally because the doc-gen crate does not need to be
published it can reference the unreleased pull request without issue.
killercup added a commit to Softleif/clap-markdown that referenced this pull request Dec 17, 2025
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