-
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
Open
leighmcculloch
wants to merge
8
commits into
ConnorGray:main
Choose a base branch
from
leighmcculloch:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5c7fe3c
Initial plan
Copilot 87aff58
Initial analysis of clap option grouping issue
Copilot 1376260
Implement support for clap argument help headings in markdown generation
Copilot 5d57b45
Add comprehensive tests and demo examples for grouped options feature
Copilot b8d58d7
fix
leighmcculloch 37b4a18
Apply code formatting fixes
Copilot f276475
Merge pull request #2 from leighmcculloch/copilot/fix-1
leighmcculloch 42956b3
remove examples
leighmcculloch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| use clap::{Arg, Command}; | ||
| use clap_markdown::{help_markdown_command_custom, MarkdownOptions}; | ||
| use pretty_assertions::assert_eq; | ||
|
|
||
| #[test] | ||
| fn test_grouped_options_by_help_heading() { | ||
| let app = Command::new("grouped-app") | ||
| .about("Test app with grouped options") | ||
| .arg( | ||
| Arg::new("verbose") | ||
| .short('v') | ||
| .long("verbose") | ||
| .help("Enable verbose output") | ||
| .help_heading("General Options") | ||
| .action(clap::ArgAction::SetTrue), | ||
| ) | ||
| .arg( | ||
| Arg::new("debug") | ||
| .short('d') | ||
| .long("debug") | ||
| .help("Enable debug output") | ||
| .help_heading("General Options") | ||
| .action(clap::ArgAction::SetTrue), | ||
| ) | ||
| .arg( | ||
| Arg::new("input") | ||
| .short('i') | ||
| .long("input") | ||
| .help("Input file") | ||
| .help_heading("File Options") | ||
| .value_name("FILE"), | ||
| ) | ||
| .arg( | ||
| Arg::new("output") | ||
| .short('o') | ||
| .long("output") | ||
| .help("Output file") | ||
| .help_heading("File Options") | ||
| .value_name("FILE"), | ||
| ) | ||
| .arg( | ||
| Arg::new("format") | ||
| .short('f') | ||
| .long("format") | ||
| .help("Output format") | ||
| .value_name("FORMAT"), // No help_heading - should go to default "Options" | ||
| ); | ||
|
|
||
| let expected_output = "\ | ||
| # Command-Line Help for `grouped-app` | ||
|
|
||
| This document contains the help content for the `grouped-app` command-line program. | ||
|
|
||
| **Command Overview:** | ||
|
|
||
| * [`grouped-app`↴](#grouped-app) | ||
|
|
||
| ## `grouped-app` | ||
|
|
||
| Test app with grouped options | ||
|
|
||
| **Usage:** `grouped-app [OPTIONS]` | ||
|
|
||
| ###### **File Options:** | ||
|
|
||
| * `-i`, `--input <FILE>` — Input file | ||
| * `-o`, `--output <FILE>` — Output file | ||
|
|
||
| ###### **General Options:** | ||
|
|
||
| * `-v`, `--verbose` — Enable verbose output | ||
| * `-d`, `--debug` — Enable debug output | ||
|
|
||
| ###### **Options:** | ||
|
|
||
| * `-f`, `--format <FORMAT>` — Output format | ||
|
|
||
|
|
||
|
|
||
| "; | ||
|
|
||
| assert_eq!( | ||
| help_markdown_command_custom( | ||
| &app, | ||
| &MarkdownOptions::new().show_footer(false) | ||
| ), | ||
| expected_output | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_no_grouped_options_backward_compatibility() { | ||
| let app = Command::new("simple-app") | ||
| .about("Test app without grouped options") | ||
| .arg( | ||
| Arg::new("verbose") | ||
| .short('v') | ||
| .long("verbose") | ||
| .help("Enable verbose output") | ||
| .action(clap::ArgAction::SetTrue), | ||
| ) | ||
| .arg( | ||
| Arg::new("output") | ||
| .short('o') | ||
| .long("output") | ||
| .help("Output file") | ||
| .value_name("FILE"), | ||
| ); | ||
|
|
||
| let expected_output = "\ | ||
| # Command-Line Help for `simple-app` | ||
|
|
||
| This document contains the help content for the `simple-app` command-line program. | ||
|
|
||
| **Command Overview:** | ||
|
|
||
| * [`simple-app`↴](#simple-app) | ||
|
|
||
| ## `simple-app` | ||
|
|
||
| Test app without grouped options | ||
|
|
||
| **Usage:** `simple-app [OPTIONS]` | ||
|
|
||
| ###### **Options:** | ||
|
|
||
| * `-v`, `--verbose` — Enable verbose output | ||
| * `-o`, `--output <FILE>` — Output file | ||
|
|
||
|
|
||
|
|
||
| "; | ||
|
|
||
| assert_eq!( | ||
| help_markdown_command_custom( | ||
| &app, | ||
| &MarkdownOptions::new().show_footer(false) | ||
| ), | ||
| expected_output | ||
| ); | ||
| } | ||
|
|
||
| #[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")); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.