Skip to content

Commit

Permalink
Merge pull request #1591 from clap-rs/issue-1589
Browse files Browse the repository at this point in the history
fixes the custom derive example in the readme
  • Loading branch information
kbknapp authored Oct 31, 2019
2 parents 269a5d2 + 9d58bbe commit 2af7c7c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,26 @@ struct Opts {
/// Some input. Because this isn't an Option<T> it's required to be used
input: String,
/// A level of verbosity, and can be used multiple times
#[clap(short = "v", long = "verbose", parse_from_occurrences)]
verbose: Option<i32>,
#[clap(short = "v", long = "verbose", parse(from_occurrences))]
verbose: i32,
#[clap(subcommand)]
subcmd: SubCommand,
}

#[derive(Clap)]
enum SubCommand {
/// A subcommand for controlling testing
#[clap(name = "test", version = "1.3", author = "Someone Else")]
Test {
/// Print debug info
#[clap(short = "d")]
debug: bool
}
Test(Test),
}

/// A subcommand for controlling testing
#[derive(Clap)]
#[clap(name = "test", version = "1.3", author = "Someone Else")]
Test {
/// Print debug info
#[clap(short = "d")]
debug: bool
}

fn main() {
let opts: Opts = Opts::parse();

Expand All @@ -201,7 +205,7 @@ fn main() {

// 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'
match opts.verbose.unwrap_or(0) {
match opts.verbose {
0 => println!("No verbose info"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
Expand All @@ -211,7 +215,7 @@ fn main() {
// 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
match opts.subcmd {
SubCommand::Test @ t => {
SubCommand::Test(t) => {
if t.debug {
println!("Printing debug info...");
} else {
Expand Down

0 comments on commit 2af7c7c

Please sign in to comment.