blob: a88adc2e5ee575924909f3eab6f437acaefd1103 [file] [log] [blame]
Matthew Maurer32e76692020-06-02 11:15:15 -07001//! How to extract subcommands' args into external structs.
David LeGare12ae7f82022-03-02 16:20:50 +00002//!
3//! Running this example with --help prints this message:
4//! -----------------------------------------------------
5//! classify 0.3.25
6//!
7//! USAGE:
8//! enum_tuple <SUBCOMMAND>
9//!
10//! FLAGS:
11//! -h, --help Prints help information
12//! -V, --version Prints version information
13//!
14//! SUBCOMMANDS:
15//! foo
16//! help Prints this message or the help of the given subcommand(s)
17//! -----------------------------------------------------
Matthew Maurer32e76692020-06-02 11:15:15 -070018
19use structopt::StructOpt;
20
21#[derive(Debug, StructOpt)]
22pub struct Foo {
23 pub bar: Option<String>,
24}
25
26#[derive(Debug, StructOpt)]
27pub enum Command {
28 #[structopt(name = "foo")]
29 Foo(Foo),
30}
31
32#[derive(Debug, StructOpt)]
33#[structopt(name = "classify")]
34pub struct ApplicationArguments {
35 #[structopt(subcommand)]
36 pub command: Command,
37}
38
39fn main() {
40 let opt = ApplicationArguments::from_args();
41 println!("{:?}", opt);
42}