Skip to content

Commit

Permalink
Merge pull request #4645 from bgilbert/mangen-flag
Browse files Browse the repository at this point in the history
fix(mangen): Avoid spurious value names for derive args without values
  • Loading branch information
epage committed Feb 22, 2023
2 parents 2a91e4f + 3755c56 commit 776f12e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clap_mangen/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions clap_mangen/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
7 changes: 7 additions & 0 deletions clap_mangen/tests/roff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
15 changes: 15 additions & 0 deletions clap_mangen/tests/snapshots/value_name_without_arg.bash.roff
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 776f12e

Please sign in to comment.