• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! How to extract subcommands' args into external structs.
2 //!
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 //! -----------------------------------------------------
18 
19 use structopt::StructOpt;
20 
21 #[derive(Debug, StructOpt)]
22 pub struct Foo {
23     pub bar: Option<String>,
24 }
25 
26 #[derive(Debug, StructOpt)]
27 pub enum Command {
28     #[structopt(name = "foo")]
29     Foo(Foo),
30 }
31 
32 #[derive(Debug, StructOpt)]
33 #[structopt(name = "classify")]
34 pub struct ApplicationArguments {
35     #[structopt(subcommand)]
36     pub command: Command,
37 }
38 
main()39 fn main() {
40     let opt = ApplicationArguments::from_args();
41     println!("{:?}", opt);
42 }
43