Skip to content

Commit

Permalink
docs(examples): Differentiate struct from command name
Browse files Browse the repository at this point in the history
This supersedes #4692
  • Loading branch information
epage committed Feb 6, 2023
1 parent 956dc6a commit 3f2625f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions examples/cargo-example-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use clap::Parser;
#[derive(Parser)] // requires `derive` feature
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
enum Cargo {
ExampleDerive(ExampleDerive),
enum CargoCli {
ExampleDerive(ExampleDeriveArgs),
}

#[derive(clap::Args)]
#[command(author, version, about, long_about = None)]
struct ExampleDerive {
struct ExampleDeriveArgs {
#[arg(long)]
manifest_path: Option<std::path::PathBuf>,
}

fn main() {
let Cargo::ExampleDerive(args) = Cargo::parse();
let CargoCli::ExampleDerive(args) = CargoCli::parse();
println!("{:?}", args.manifest_path);
}
4 changes: 2 additions & 2 deletions examples/git-derive.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ Options:
-h, --help Print help

$ git-derive stash -m "Prototype"
Pushing StashPush { message: Some("Prototype") }
Pushing StashPushArgs { message: Some("Prototype") }

$ git-derive stash pop
Popping None

$ git-derive stash push -m "Prototype"
Pushing StashPush { message: Some("Prototype") }
Pushing StashPushArgs { message: Some("Prototype") }

$ git-derive stash pop
Popping None
Expand Down
10 changes: 5 additions & 5 deletions examples/git-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum Commands {
#[arg(required = true)]
path: Vec<PathBuf>,
},
Stash(Stash),
Stash(StashArgs),
#[command(external_subcommand)]
External(Vec<OsString>),
}
Expand All @@ -76,23 +76,23 @@ impl std::fmt::Display for ColorWhen {

#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct Stash {
struct StashArgs {
#[command(subcommand)]
command: Option<StashCommands>,

#[command(flatten)]
push: StashPush,
push: StashPushArgs,
}

#[derive(Debug, Subcommand)]
enum StashCommands {
Push(StashPush),
Push(StashPushArgs),
Pop { stash: Option<String> },
Apply { stash: Option<String> },
}

#[derive(Debug, Args)]
struct StashPush {
struct StashPushArgs {
#[arg(short, long)]
message: Option<String>,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_derive/03_04_subcommands_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Adds files to myapp
Add(Add),
Add(AddArgs),
}

#[derive(Args)]
struct Add {
struct AddArgs {
name: Option<String>,
}

Expand Down

0 comments on commit 3f2625f

Please sign in to comment.