2020-01-07 10:17:23 +00:00
|
|
|
//! How to extract subcommands' args into external structs.
|
2018-01-30 17:38:35 +00:00
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::Parser;
|
2018-01-30 17:38:35 +00:00
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2018-01-30 17:38:35 +00:00
|
|
|
pub struct Foo {
|
|
|
|
pub bar: Option<String>,
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2018-01-30 17:38:35 +00:00
|
|
|
pub enum Command {
|
2018-07-02 18:45:17 +00:00
|
|
|
#[clap(name = "foo")]
|
2018-05-21 14:54:22 +00:00
|
|
|
Foo(Foo),
|
2018-01-30 17:38:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2018-07-02 18:45:17 +00:00
|
|
|
#[clap(name = "classify")]
|
2018-01-30 17:38:35 +00:00
|
|
|
pub struct ApplicationArguments {
|
2018-07-02 18:45:17 +00:00
|
|
|
#[clap(subcommand)]
|
2018-01-30 17:38:35 +00:00
|
|
|
pub command: Command,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-07-02 18:45:17 +00:00
|
|
|
let opt = ApplicationArguments::parse();
|
2018-01-30 17:38:35 +00:00
|
|
|
println!("{:?}", opt);
|
|
|
|
}
|