Matthew Maurer | 32e7669 | 2020-06-02 11:15:15 -0700 | [diff] [blame] | 1 | //! How to extract subcommands' args into external structs. |
David LeGare | 12ae7f8 | 2022-03-02 16:20:50 +0000 | [diff] [blame] | 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 | //! ----------------------------------------------------- |
Matthew Maurer | 32e7669 | 2020-06-02 11:15:15 -0700 | [diff] [blame] | 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 | |
| 39 | fn main() { |
| 40 | let opt = ApplicationArguments::from_args(); |
| 41 | println!("{:?}", opt); |
| 42 | } |