diff --git a/clap_mangen/Cargo.toml b/clap_mangen/Cargo.toml index 8f82e5c0f19..74922c9e7a7 100644 --- a/clap_mangen/Cargo.toml +++ b/clap_mangen/Cargo.toml @@ -45,7 +45,7 @@ clap = { path = "../", version = "4.0.0", default-features = false, features = [ [dev-dependencies] snapbox = { version = "0.4", features = ["diff"] } -clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] } +clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help", "derive"] } [features] default = [] diff --git a/clap_mangen/tests/common.rs b/clap_mangen/tests/common.rs index 8c830338400..ca9f1f9b4fb 100644 --- a/clap_mangen/tests/common.rs +++ b/clap_mangen/tests/common.rs @@ -312,17 +312,3 @@ pub fn possible_values_command(name: &'static str) -> clap::Command { ]), ) } - -/// Checks to make sure boolean valued "Flag options" do not generate -/// suggestions for a parameter. i.e: -/// --boolean_flag=BOOLEAN_FLAG -/// -/// This is both confusing and suggest erroneous behavior as clap will fail if you -/// pass a value to a boolean flag -pub fn flag_without_value(name: &'static str) -> clap::Command { - clap::Command::new(name).arg( - clap::Arg::new("is_bool") - .long("is_bool") - .action(clap::ArgAction::SetTrue), - ) -} diff --git a/clap_mangen/tests/derive.rs b/clap_mangen/tests/derive.rs new file mode 100644 index 00000000000..557b62a103f --- /dev/null +++ b/clap_mangen/tests/derive.rs @@ -0,0 +1,36 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser, Debug)] +#[command(name = "my-app")] +pub struct BasicCommand { + #[clap(short, global = true)] + config: bool, + + #[clap(short, conflicts_with("config"))] + v: bool, + + #[command(subcommand)] + test: Option, +} + +#[derive(Subcommand, Debug)] +pub enum BasicCommandSubCommand { + /// Subcommand + Test { + #[clap(short, action(clap::ArgAction::Count))] + debug: u8, + }, +} + +// Checks to make sure boolean valued "Flag options" do not generate +// suggestions for a parameter. i.e: +// --boolean_flag=BOOLEAN_FLAG +// +// This is both confusing and suggest erroneous behavior as clap will fail if you +// pass a value to a boolean flag +#[derive(Parser, Debug)] +#[command(name = "my-app")] +pub struct FlagWithoutValue { + #[clap(long)] + boolean_flag: bool, +} diff --git a/clap_mangen/tests/roff.rs b/clap_mangen/tests/roff.rs index 4d47d249f45..71916e62a40 100644 --- a/clap_mangen/tests/roff.rs +++ b/clap_mangen/tests/roff.rs @@ -1,4 +1,7 @@ mod common; +mod derive; + +use clap::CommandFactory; #[test] fn basic() { @@ -72,11 +75,16 @@ fn possible_values() { #[test] fn flag_without_value() { - let name = "my-app"; - let cmd = common::flag_without_value(name); + let cmd = derive::FlagWithoutValue::command(); common::assert_matches_path("tests/snapshots/flag_without_value.bash.roff", cmd); } +#[test] +fn derive_basic_command() { + let cmd = derive::BasicCommand::command(); + common::assert_matches_path("tests/snapshots/basic.bash.roff", cmd); +} + #[test] fn sub_subcommands_help() { let name = "my-app"; diff --git a/clap_mangen/tests/snapshots/flag_without_value.bash.roff b/clap_mangen/tests/snapshots/flag_without_value.bash.roff index b4b7f45cb68..9ee57879400 100644 --- a/clap_mangen/tests/snapshots/flag_without_value.bash.roff +++ b/clap_mangen/tests/snapshots/flag_without_value.bash.roff @@ -4,11 +4,11 @@ .SH NAME my/-app .SH SYNOPSIS -/fBmy/-app/fR [/fB/-/-is_bool/fR] [/fB/-h/fR|/fB/-/-help/fR] +/fBmy/-app/fR [/fB/-/-boolean/-flag/fR] [/fB/-h/fR|/fB/-/-help/fR] .SH DESCRIPTION .SH OPTIONS .TP -/fB/-/-is_bool/fR +/fB/-/-boolean/-flag/fR .TP /fB/-h/fR, /fB/-/-help/fR