mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
Merge pull request #1591 from clap-rs/issue-1589
fixes the custom derive example in the readme
This commit is contained in:
commit
2af7c7ca34
1 changed files with 15 additions and 11 deletions
20
README.md
20
README.md
|
@ -176,22 +176,26 @@ struct Opts {
|
||||||
/// Some input. Because this isn't an Option<T> it's required to be used
|
/// Some input. Because this isn't an Option<T> it's required to be used
|
||||||
input: String,
|
input: String,
|
||||||
/// A level of verbosity, and can be used multiple times
|
/// A level of verbosity, and can be used multiple times
|
||||||
#[clap(short = "v", long = "verbose", parse_from_occurrences)]
|
#[clap(short = "v", long = "verbose", parse(from_occurrences))]
|
||||||
verbose: Option<i32>,
|
verbose: i32,
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
subcmd: SubCommand,
|
subcmd: SubCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clap)]
|
#[derive(Clap)]
|
||||||
enum SubCommand {
|
enum SubCommand {
|
||||||
/// A subcommand for controlling testing
|
Test(Test),
|
||||||
#[clap(name = "test", version = "1.3", author = "Someone Else")]
|
}
|
||||||
Test {
|
|
||||||
|
/// A subcommand for controlling testing
|
||||||
|
#[derive(Clap)]
|
||||||
|
#[clap(name = "test", version = "1.3", author = "Someone Else")]
|
||||||
|
Test {
|
||||||
/// Print debug info
|
/// Print debug info
|
||||||
#[clap(short = "d")]
|
#[clap(short = "d")]
|
||||||
debug: bool
|
debug: bool
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let opts: Opts = Opts::parse();
|
let opts: Opts = Opts::parse();
|
||||||
|
|
||||||
|
@ -201,7 +205,7 @@ fn main() {
|
||||||
|
|
||||||
// Vary the output based on how many times the user used the "verbose" flag
|
// Vary the output based on how many times the user used the "verbose" flag
|
||||||
// (i.e. 'myprog -v -v -v' or 'myprog -vvv' vs 'myprog -v'
|
// (i.e. 'myprog -v -v -v' or 'myprog -vvv' vs 'myprog -v'
|
||||||
match opts.verbose.unwrap_or(0) {
|
match opts.verbose {
|
||||||
0 => println!("No verbose info"),
|
0 => println!("No verbose info"),
|
||||||
1 => println!("Some verbose info"),
|
1 => println!("Some verbose info"),
|
||||||
2 => println!("Tons of verbose info"),
|
2 => println!("Tons of verbose info"),
|
||||||
|
@ -211,7 +215,7 @@ fn main() {
|
||||||
// You can handle information about subcommands by requesting their matches by name
|
// You can handle information about subcommands by requesting their matches by name
|
||||||
// (as below), requesting just the name used, or both at the same time
|
// (as below), requesting just the name used, or both at the same time
|
||||||
match opts.subcmd {
|
match opts.subcmd {
|
||||||
SubCommand::Test @ t => {
|
SubCommand::Test(t) => {
|
||||||
if t.debug {
|
if t.debug {
|
||||||
println!("Printing debug info...");
|
println!("Printing debug info...");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue