Matthew Maurer | 32e7669 | 2020-06-02 11:15:15 -0700 | [diff] [blame^] | 1 | //! How to extract subcommands' args into external structs. |
| 2 | |
| 3 | use structopt::StructOpt; |
| 4 | |
| 5 | #[derive(Debug, StructOpt)] |
| 6 | pub struct Foo { |
| 7 | pub bar: Option<String>, |
| 8 | } |
| 9 | |
| 10 | #[derive(Debug, StructOpt)] |
| 11 | pub enum Command { |
| 12 | #[structopt(name = "foo")] |
| 13 | Foo(Foo), |
| 14 | } |
| 15 | |
| 16 | #[derive(Debug, StructOpt)] |
| 17 | #[structopt(name = "classify")] |
| 18 | pub struct ApplicationArguments { |
| 19 | #[structopt(subcommand)] |
| 20 | pub command: Command, |
| 21 | } |
| 22 | |
| 23 | fn main() { |
| 24 | let opt = ApplicationArguments::from_args(); |
| 25 | println!("{:?}", opt); |
| 26 | } |