From 7030e9e995d7ed0e3856d3efb50e93e25a90a429 Mon Sep 17 00:00:00 2001 From: Daniel Rivas Date: Sun, 30 Oct 2022 16:29:58 +0000 Subject: [PATCH] fix: Don't show default values for flags Also show ellipsis for repeatable arguments. --- clap_mangen/src/render.rs | 13 ++++++++----- clap_mangen/tests/snapshots/aliases.bash.roff | 2 +- clap_mangen/tests/snapshots/basic.bash.roff | 4 ++-- .../tests/snapshots/feature_sample.bash.roff | 4 ++-- clap_mangen/tests/snapshots/quoting.bash.roff | 12 ++++++------ .../tests/snapshots/special_commands.bash.roff | 4 ++-- .../tests/snapshots/sub_subcommands.bash.roff | 4 ++-- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index e4b09f567b5..08da00e73bd 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -1,3 +1,4 @@ +use clap::ArgAction; use roff::{bold, italic, roman, Inline, Roff}; pub(crate) fn subcommand_heading(cmd: &clap::Command) -> &str { @@ -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() { @@ -306,7 +309,7 @@ fn option_environment(opt: &clap::Arg) -> Option> { } fn option_default_values(opt: &clap::Arg) -> Option { - 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 diff --git a/clap_mangen/tests/snapshots/aliases.bash.roff b/clap_mangen/tests/snapshots/aliases.bash.roff index 959dfaa3edd..4cd893f1f25 100644 --- a/clap_mangen/tests/snapshots/aliases.bash.roff +++ b/clap_mangen/tests/snapshots/aliases.bash.roff @@ -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 diff --git a/clap_mangen/tests/snapshots/basic.bash.roff b/clap_mangen/tests/snapshots/basic.bash.roff index b0e0f5b14ea..e502cd97a99 100644 --- a/clap_mangen/tests/snapshots/basic.bash.roff +++ b/clap_mangen/tests/snapshots/basic.bash.roff @@ -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 diff --git a/clap_mangen/tests/snapshots/feature_sample.bash.roff b/clap_mangen/tests/snapshots/feature_sample.bash.roff index ad89abedc84..f3cc3bf6125 100644 --- a/clap_mangen/tests/snapshots/feature_sample.bash.roff +++ b/clap_mangen/tests/snapshots/feature_sample.bash.roff @@ -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 diff --git a/clap_mangen/tests/snapshots/quoting.bash.roff b/clap_mangen/tests/snapshots/quoting.bash.roff index 7ca1e33241f..60280b4255c 100644 --- a/clap_mangen/tests/snapshots/quoting.bash.roff +++ b/clap_mangen/tests/snapshots/quoting.bash.roff @@ -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 diff --git a/clap_mangen/tests/snapshots/special_commands.bash.roff b/clap_mangen/tests/snapshots/special_commands.bash.roff index 0cf113f8cbc..db7b607a49d 100644 --- a/clap_mangen/tests/snapshots/special_commands.bash.roff +++ b/clap_mangen/tests/snapshots/special_commands.bash.roff @@ -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 diff --git a/clap_mangen/tests/snapshots/sub_subcommands.bash.roff b/clap_mangen/tests/snapshots/sub_subcommands.bash.roff index f2a22e9de50..9f034036a2c 100644 --- a/clap_mangen/tests/snapshots/sub_subcommands.bash.roff +++ b/clap_mangen/tests/snapshots/sub_subcommands.bash.roff @@ -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