Merge pull request #3605 from ducaale/synopsis-hidden-flags

Don't include hidden flags in the synopsis section from clap_mangen
This commit is contained in:
Ed Page 2022-04-02 19:59:50 -05:00 committed by GitHub
commit e91d18ba0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View file

@ -31,7 +31,7 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) {
pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
let mut line = vec![bold(cmd.get_name()), roman(" ")];
for opt in cmd.get_arguments() {
for opt in cmd.get_arguments().filter(|i| !i.is_hide_set()) {
let (lhs, rhs) = option_markers(opt);
match (opt.get_short(), opt.get_long()) {
(Some(short), Some(long)) => {

View file

@ -220,6 +220,17 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> {
)
}
pub fn hidden_option_command(name: &'static str) -> clap::Command<'static> {
clap::Command::new(name)
.arg(clap::Arg::new("config").long("--config").takes_value(true))
.arg(
clap::Arg::new("no-config")
.long("--no-config")
.hide(true)
.overrides_with("config"),
)
}
pub fn assert_matches_path(expected_path: impl AsRef<std::path::Path>, cmd: clap::Command) {
let mut buf = vec![];
clap_mangen::Man::new(cmd).render(&mut buf).unwrap();

View file

@ -48,3 +48,10 @@ fn value_hint() {
let cmd = common::value_hint_command(name);
common::assert_matches_path("tests/snapshots/value_hint.bash.roff", cmd);
}
#[test]
fn hidden_options() {
let name = "my-app";
let cmd = common::hidden_option_command(name);
common::assert_matches_path("tests/snapshots/hidden_option.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/-h/fR|/fB/-/-help/fR] [/fB/-/-config/fR]
.SH DESCRIPTION
.SH OPTIONS
.TP
/fB/-h/fR, /fB/-/-help/fR
Print help information
.TP
/fB/-/-config/fR