Skip to content

Commit

Permalink
Merge pull request #4432 from drivasperez/fix-man-args
Browse files Browse the repository at this point in the history
clap_mangen: Don't show default values for flags, show ellipsis for repeatable arguments
  • Loading branch information
epage authored Oct 31, 2022
2 parents e14bd0e + 7030e9e commit 5908192
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
13 changes: 8 additions & 5 deletions clap_mangen/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::ArgAction;
use roff::{bold, italic, roman, Inline, Roff};

pub(crate) fn subcommand_heading(cmd: &clap::Command) -> &str {
Expand Down Expand Up @@ -39,22 +40,24 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
line.push(roman("|"));
line.push(bold(&format!("--{}", long)));
line.push(roman(rhs));
line.push(roman(" "));
}
(Some(short), None) => {
line.push(roman(lhs));
line.push(bold(&format!("-{} ", short)));
line.push(roman(rhs));
line.push(roman(" "));
}
(None, Some(long)) => {
line.push(roman(lhs));
line.push(bold(&format!("--{}", long)));
line.push(roman(rhs));
line.push(roman(" "));
}
(None, None) => (),
(None, None) => continue,
};

if matches!(opt.get_action(), ArgAction::Count) {
line.push(roman("..."))
}
line.push(roman(" "));
}

for arg in cmd.get_positionals() {
Expand Down Expand Up @@ -306,7 +309,7 @@ fn option_environment(opt: &clap::Arg) -> Option<Vec<Inline>> {
}

fn option_default_values(opt: &clap::Arg) -> Option<String> {
if opt.is_hide_default_value_set() {
if opt.is_hide_default_value_set() || !opt.get_action().takes_values() {
return None;
} else if !opt.get_default_values().is_empty() {
let values = opt
Expand Down
2 changes: 1 addition & 1 deletion clap_mangen/tests/snapshots/aliases.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ my/-app /- testing bash completions
testing bash completions
.SH OPTIONS
.TP
/fB/-f/fR, /fB/-/-flag/fR [default: false]
/fB/-f/fR, /fB/-/-flag/fR
cmd flag
.TP
/fB/-o/fR, /fB/-/-option/fR
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/tests/snapshots/basic.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ my/-app
.SH DESCRIPTION
.SH OPTIONS
.TP
/fB/-c/fR [default: false]
/fB/-c/fR

.TP
/fB/-v/fR [default: false]
/fB/-v/fR

.TP
/fB/-h/fR, /fB/-/-help/fR
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/tests/snapshots/feature_sample.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
.SH NAME
my/-app /- Tests completions
.SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
.SH DESCRIPTION
Tests completions
.SH OPTIONS
.TP
/fB/-c/fR, /fB/-/-config/fR [default: 0]
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
/fB/-h/fR, /fB/-/-help/fR
Expand Down
12 changes: 6 additions & 6 deletions clap_mangen/tests/snapshots/quoting.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ my/-app
.SH DESCRIPTION
.SH OPTIONS
.TP
/fB/-/-single/-quotes/fR [default: false]
/fB/-/-single/-quotes/fR
Can be /*(Aqalways/*(Aq, /*(Aqauto/*(Aq, or /*(Aqnever/*(Aq
.TP
/fB/-/-double/-quotes/fR [default: false]
/fB/-/-double/-quotes/fR
Can be "always", "auto", or "never"
.TP
/fB/-/-backticks/fR [default: false]
/fB/-/-backticks/fR
For more information see `echo test`
.TP
/fB/-/-backslash/fR [default: false]
/fB/-/-backslash/fR
Avoid /*(Aq//n/*(Aq
.TP
/fB/-/-brackets/fR [default: false]
/fB/-/-brackets/fR
List packages [filter]
.TP
/fB/-/-expansions/fR [default: false]
/fB/-/-expansions/fR
Execute the shell command with $SHELL
.TP
/fB/-h/fR, /fB/-/-help/fR
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/tests/snapshots/special_commands.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
.SH NAME
my/-app /- Tests completions
.SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
.SH DESCRIPTION
Tests completions
.SH OPTIONS
.TP
/fB/-c/fR, /fB/-/-config/fR [default: 0]
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
/fB/-h/fR, /fB/-/-help/fR
Expand Down
4 changes: 2 additions & 2 deletions clap_mangen/tests/snapshots/sub_subcommands.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
.SH NAME
my/-app /- Tests completions
.SH SYNOPSIS
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR] [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
/fBmy/-app/fR [/fB/-c/fR|/fB/-/-config/fR]... [/fB/-h/fR|/fB/-/-help/fR] [/fB/-V/fR|/fB/-/-version/fR] [/fIfile/fR] [/fIchoice/fR] [/fIsubcommands/fR]
.SH DESCRIPTION
Tests completions
.SH OPTIONS
.TP
/fB/-c/fR, /fB/-/-config/fR [default: 0]
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
/fB/-h/fR, /fB/-/-help/fR
Expand Down

0 comments on commit 5908192

Please sign in to comment.