use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Parser, Debug)]
#[clap(version, about)]
pub struct Cli {
#[clap(subcommand)]
pub command: Command,
}
impl Cli {
pub fn new() -> Command {
Self::parse().command
}
}
#[derive(Subcommand, Debug)]
pub enum Command {
#[clap(aliases = &["q", "search", "s"])]
Query(QueryArgs),
#[clap(aliases = &["e", "config"])]
Edit(EditArgs),
#[clap(aliases = &["c"])]
Clean,
}
#[derive(Args, Debug)]
pub struct QueryArgs {
#[clap(value_parser)]
pub query: String,
#[clap(value_parser, short, long)]
pub speak: bool,
#[clap(value_parser, long)]
pub speak_as: Option<Toggle>,
#[clap(value_parser, short, long)]
pub concise: bool,
#[clap(value_parser, long)]
pub concise_as: Option<Toggle>,
}
#[derive(Args, Debug)]
pub struct EditArgs {
#[clap(value_parser, long)]
pub reset: bool,
}
#[derive(Clone, Debug, ValueEnum)]
pub enum Toggle {
True,
False,
Flip,
}
impl Toggle {
pub fn twitch(&self, b: &mut bool) {
match self {
Toggle::True => *b = true,
Toggle::False => *b = false,
Toggle::Flip => *b = !*b,
}
}
pub fn counter_twitch(&self, b: &mut bool) {
match self {
Toggle::True => *b = false,
Toggle::False => *b = true,
Toggle::Flip => *b = !*b,
}
}
}