use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Parser, Debug)]
#[clap(version, about)]
pub struct Cli {
#[clap(subcommand)]
pub commands: Commands,
}
impl Cli {
pub fn new() -> Commands {
Self::parse().commands
}
}
#[derive(Subcommand, Debug)]
pub enum Commands {
#[clap(aliases = &["q", "search", "s"])]
Query(QueryArgs),
#[clap(aliases = &["e", "config"])]
Edit(EditArgs),
#[clap(aliases = &["c"])]
Cache {
#[clap(subcommand)]
commands: CacheCmds,
},
}
#[derive(Args, Debug)]
pub struct QueryArgs {
#[clap(value_parser)]
pub query: Vec<String>,
#[clap(value_parser, short, long)]
pub speak: bool,
#[clap(value_parser, short = 'q', long)]
pub mute: 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>,
}
impl QueryArgs {
pub fn query(&self) -> String {
self.query.join(" ")
}
}
#[derive(Args, Debug)]
pub struct EditArgs {
#[clap(value_parser, long)]
pub reset: bool,
}
#[derive(Subcommand, Debug)]
pub enum CacheCmds {
#[clap(aliases = &["ls"])]
Show,
#[clap(aliases = &["destroy"])]
Clean,
#[clap(aliases = &["in"])]
Import {
#[clap(value_parser)]
dir: PathBuf,
},
#[clap(aliases = &["out"])]
Export {
#[clap(value_parser)]
dir: PathBuf,
},
}
#[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,
}
}
}