-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(mangen): Support flatten_help #5769
Open
aparcar
wants to merge
4
commits into
clap-rs:master
Choose a base branch
from
aparcar:flat-man
base: master
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,26 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH my-app 1 "my-app " | ||
.SH NAME | ||
my\-app | ||
.SH SYNOPSIS | ||
\fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] | ||
.SH DESCRIPTION | ||
.SH OPTIONS | ||
.TP | ||
\fB\-c\fR | ||
|
||
.TP | ||
\fB\-v\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
my\-app\-test(1) | ||
Subcommand | ||
with a second line | ||
.TP | ||
my\-app\-help(1) | ||
Print this message or the help of the given subcommand(s) |
26 changes: 26 additions & 0 deletions
26
clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff
This file contains 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,26 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH my-app 1 "my-app " | ||
.SH NAME | ||
my\-app | ||
.SH SYNOPSIS | ||
\fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] <\fIsubcommands\fR> | ||
.SH DESCRIPTION | ||
.SH OPTIONS | ||
.TP | ||
\fB\-c\fR | ||
|
||
.TP | ||
\fB\-v\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
my\-app\-test(1) | ||
Subcommand | ||
with a second line | ||
.TP | ||
my\-app\-help(1) | ||
Print this message or the help of the given subcommand(s) |
This file contains 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 |
---|---|---|
|
@@ -105,3 +105,39 @@ fn value_name_without_arg() { | |
cmd, | ||
); | ||
} | ||
|
||
#[test] | ||
fn flatten_help_false() { | ||
let name = "my-app"; | ||
let cmd = common::basic_command(name).flatten_help(false); | ||
common::assert_matches(snapbox::file!["../snapshots/basic.bash.roff"], cmd); | ||
} | ||
|
||
#[test] | ||
fn flatten_help_true() { | ||
let name = "my-app"; | ||
let cmd = common::basic_command(name).flatten_help(true); | ||
common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); | ||
} | ||
|
||
#[test] | ||
fn flatten_help_true_subcommand_required_true() { | ||
let name = "my-app"; | ||
let cmd = common::basic_command(name) | ||
.flatten_help(true) | ||
.subcommand_required(true); | ||
common::assert_matches( | ||
snapbox::file!["../snapshots/flatten_help_subcommand_required.roff"], | ||
cmd, | ||
); | ||
} | ||
|
||
#[test] | ||
fn flatten_help_true_subcommand_args_conflicts_with_subcommands() { | ||
Comment on lines
+117
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these tests still needed with the addition of the |
||
let name = "my-app"; | ||
let cmd = common::basic_command(name) | ||
.flatten_help(true) | ||
.subcommand_required(false) | ||
.args_conflicts_with_subcommands(false); | ||
common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); | ||
} | ||
epage marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
We should probably cover more cases that
help
covers, seeclap/tests/builder/help.rs
Lines 3280 to 3971 in 61f5ee5
e.g.
It'd be a big help to reuse the same commands as those tests so we can easily compare the help output vs man 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.
I added all relevant tests from
help.rs
and at least the recursive stuff isn't working right now. Is the recursive stuff strictly required for this PR to move forward?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.
The recursive behavior is part of the definition of
flatten_help
. We could possibly split it out but we'd need to be tracking it somehow. Its likely best to go ahead and do that as it might affect the design in important ways