Merge pull request #4645 from bgilbert/mangen-flag

fix(mangen): Avoid spurious value names for derive args without values
This commit is contained in:
Ed Page 2023-02-22 16:14:21 -06:00 committed by GitHub
commit 776f12ebb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 3 deletions

View file

@ -99,9 +99,11 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
(None, None) => vec![],
};
if let Some(value) = &opt.get_value_names() {
header.push(roman("="));
header.push(italic(value.join(" ")));
if opt.get_action().takes_values() {
if let Some(value) = &opt.get_value_names() {
header.push(roman("="));
header.push(italic(value.join(" ")));
}
}
if let Some(defs) = option_default_values(opt) {

View file

@ -312,3 +312,12 @@ pub fn possible_values_command(name: &'static str) -> clap::Command {
]),
)
}
pub fn value_name_without_arg(name: &'static str) -> clap::Command {
clap::Command::new(name).arg(
clap::Arg::new("flag")
.long("flag")
.value_name("SPURIOUS")
.action(clap::ArgAction::SetTrue),
)
}

View file

@ -83,3 +83,10 @@ fn sub_subcommands_help() {
common::assert_matches_path("tests/snapshots/sub_subcommand_help.roff", cmd.clone());
}
}
#[test]
fn value_name_without_arg() {
let name = "my-app";
let cmd = common::value_name_without_arg(name);
common::assert_matches_path("tests/snapshots/value_name_without_arg.bash.roff", cmd);
}

View file

@ -0,0 +1,15 @@
.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/-/-flag/fR] [/fB/-h/fR|/fB/-/-help/fR]
.SH DESCRIPTION
.SH OPTIONS
.TP
/fB/-/-flag/fR
.TP
/fB/-h/fR, /fB/-/-help/fR
Print help