forked from clap-rs/clap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test of derive functionality
It was noticed that between clap-rs#4443 and clap-rs#4432, an issue in the behavior was that the derive api handles tasks with values slightly differently than the declarative api. Added a test to show parity between declaritive and derive api.
- Loading branch information
Showing
5 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BasicCommandSubCommand>, | ||
} | ||
|
||
#[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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters