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