-
Notifications
You must be signed in to change notification settings - Fork 26
Support grouped options in markdown output #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: leighmcculloch <[email protected]>
Co-authored-by: leighmcculloch <[email protected]>
Co-authored-by: leighmcculloch <[email protected]>
Co-authored-by: leighmcculloch <[email protected]>
Implement support for clap argument help headings in markdown generation
| #[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")); | ||
| } |
There was a problem hiding this comment.
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.
killercup
left a comment
There was a problem hiding this 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 :)
### 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.
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:
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