1use std::path::PathBuf;
2
3use clap::{Args, Parser, Subcommand, ValueEnum};
4
5#[derive(Parser, Debug)]
6#[clap(version, about, long_about = None)]
7pub struct Cli {
8 #[clap(subcommand)]
9 pub commands: Commands,
10}
11
12impl Cli {
13 pub fn new() -> Commands {
14 Self::parse().commands
15 }
16}
17
18#[derive(Subcommand, Debug)]
19pub enum Commands {
20 #[clap(aliases = &["q", "search", "s"])]
22 Query(QueryArgs),
23 #[clap(aliases = &["e", "config"])]
25 Edit(EditArgs),
26 #[clap(aliases = &["c"])]
28 Cache {
29 #[clap(subcommand)]
30 commands: CacheCmds,
31 },
32}
33
34#[derive(Args, Debug)]
35pub struct QueryArgs {
36 #[clap(value_parser)]
38 pub query: Vec<String>,
39 #[clap(value_parser, short, long)]
41 pub speak: bool,
42 #[clap(value_parser, short = 'q', long)]
44 pub mute: bool,
45 #[clap(value_parser, long)]
47 pub speak_as: Option<Toggle>,
48 #[clap(value_parser, short, long)]
50 pub concise: bool,
51 #[clap(value_parser, long)]
53 pub concise_as: Option<Toggle>,
54}
55
56impl QueryArgs {
57 pub fn query(&self) -> String {
58 self.query.join(" ")
59 }
60}
61
62#[derive(Args, Debug)]
63pub struct EditArgs {
64 #[clap(value_parser, long)]
66 pub reset: bool,
67}
68
69#[derive(Subcommand, Debug)]
70pub enum CacheCmds {
71 #[clap(aliases = &["ls"])]
73 Show,
74 #[clap(aliases = &["destroy"])]
76 Clean,
77 #[clap(aliases = &["in"])]
79 Import {
80 #[clap(value_parser)]
81 dir: PathBuf,
82 },
83 #[clap(aliases = &["out"])]
85 Export {
86 #[clap(value_parser)]
87 dir: PathBuf,
88 },
89}
90
91#[derive(Clone, Debug, ValueEnum)]
92pub enum Toggle {
93 True,
95 False,
97 Flip,
99}
100
101impl Toggle {
102 pub fn twitch(&self, b: &mut bool) {
103 match self {
104 Toggle::True => *b = true,
105 Toggle::False => *b = false,
106 Toggle::Flip => *b = !*b,
107 }
108 }
109 pub fn counter_twitch(&self, b: &mut bool) {
110 match self {
111 Toggle::True => *b = false,
112 Toggle::False => *b = true,
113 Toggle::Flip => *b = !*b,
114 }
115 }
116}