use cote::prelude::*;
#[derive(Debug, Cote, PartialEq, Eq)]
#[cote(help, aborthelp)]
pub struct Cli {
#[arg(alias = "-g")]
age: usize,
#[sub(alias = "e")]
eat: Option<Eat>,
#[sub(
prepolicy,
head = "This is head message of sport sub command.",
foot = "This is foot message of sport sub command."
)]
sport: Option<Sport>,
}
#[derive(Debug, Cote, PartialEq, Eq)]
#[cote(help, aborthelp)]
pub struct Eat {
#[arg(alias = "-m")]
meal: String,
#[pos(value = "rice")]
what: Option<String>,
}
#[derive(Debug, Cote, PartialEq, Eq)]
#[cote(help, aborthelp)]
pub struct Sport {
#[sub(hint = "[walk]")]
walk: Option<Walk>,
#[sub(hint = "[play]")]
play: Option<Play>,
}
#[derive(Debug, Cote, PartialEq, Eq)]
#[cote(help, aborthelp)]
pub struct Walk {
#[arg(name = "-d", value = 3usize)]
distance: usize,
}
#[derive(Debug, Cote, PartialEq, Eq)]
#[cote(help, aborthelp)]
pub struct Play {
#[pos(value = "Mario")]
game: String,
}
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let cli = Cli::parse_env()?;
println!("You age is set to {}", cli.age);
if let Some(eat) = cli.eat {
println!("You {} are going to eat {}", eat.meal, eat.what.unwrap());
} else if let Some(sport) = cli.sport {
if let Some(walk) = sport.walk {
println!("You are going to walk {} kilometers", walk.distance);
} else if let Some(play) = sport.play {
println!("You are going to play game {}", play.game);
}
}
Ok(())
}