1use {
3 clap::{
4 Parser,
5 ValueEnum,
6 },
7 std::{
8 path::PathBuf,
9 str::FromStr,
10 },
11};
12
13#[derive(Debug, Parser)]
15#[command(about, version, disable_version_flag = true, disable_help_flag = true)]
16pub struct Args {
17 #[arg(long)]
19 pub help: bool,
20
21 #[arg(long)]
23 pub version: bool,
24
25 #[arg(long, value_name = "paths")]
27 pub conf: Option<String>,
28
29 #[arg(short, long)]
31 pub dates: bool,
32
33 #[arg(short = 'D', long)]
35 pub no_dates: bool,
36
37 #[arg(short = 'f', long)]
38 pub only_folders: bool,
40
41 #[arg(short = 'F', long)]
43 pub no_only_folders: bool,
44
45 #[arg(long)]
47 pub show_root_fs: bool,
48
49 #[arg(long)]
51 pub max_depth: Option<u16>,
52
53 #[arg(short = 'g', long)]
55 pub show_git_info: bool,
56
57 #[arg(short = 'G', long)]
59 pub no_show_git_info: bool,
60
61 #[arg(long)]
62 pub git_status: bool,
64
65 #[arg(short = 'h', long)]
66 pub hidden: bool,
68
69 #[arg(short = 'H', long)]
70 pub no_hidden: bool,
72
73 #[arg(short = 'i', long)]
74 pub git_ignored: bool,
76
77 #[arg(short = 'I', long)]
78 pub no_git_ignored: bool,
80
81 #[arg(short = 'p', long)]
82 pub permissions: bool,
84
85 #[arg(short = 'P', long)]
86 pub no_permissions: bool,
88
89 #[arg(short = 's', long)]
90 pub sizes: bool,
92
93 #[arg(short = 'S', long)]
94 pub no_sizes: bool,
96
97 #[arg(long)]
98 pub sort_by_count: bool,
100
101 #[arg(long)]
102 pub sort_by_date: bool,
104
105 #[arg(long)]
106 pub sort_by_size: bool,
108
109 #[arg(long)]
110 pub sort_by_type: bool,
112
113 #[arg(long)]
114 pub no_tree: bool,
116
117 #[arg(long)]
118 pub tree: bool,
120
121 #[arg(long)]
122 pub sort_by_type_dirs_first: bool,
124
125 #[arg(long)]
126 pub sort_by_type_dirs_last: bool,
128
129 #[arg(long)]
131 pub no_sort: bool,
132
133 #[arg(short, long)]
135 pub whale_spotting: bool,
136
137 #[arg(short = 'W', long)]
139 pub no_whale_spotting: bool,
140
141 #[arg(short = 't', long)]
143 pub trim_root: bool,
144
145 #[arg(short = 'T', long)]
147 pub no_trim_root: bool,
148
149 #[arg(long, value_name = "path")]
151 pub outcmd: Option<PathBuf>,
152
153 #[arg(long, value_name = "verb-output")]
155 pub verb_output: Option<PathBuf>,
156
157 #[arg(short, long, value_name = "cmd")]
159 pub cmd: Option<String>,
160
161 #[arg(long, default_value = "auto", value_name = "color")]
163 pub color: TriBool,
164
165 #[arg(long, value_name = "height")]
167 pub height: Option<u16>,
168
169 #[arg(long)]
171 pub install: bool,
172
173 #[arg(long, value_name = "state")]
175 pub set_install_state: Option<CliShellInstallState>,
176
177 #[arg(long, value_name = "shell")]
179 pub print_shell_function: Option<String>,
180
181 #[cfg(unix)]
183 #[arg(long, value_name = "socket")]
184 pub listen: Option<String>,
185
186 #[cfg(unix)]
188 #[arg(long)]
189 pub listen_auto: bool,
190
191 #[cfg(unix)]
193 #[arg(long)]
194 pub get_root: bool,
195
196 #[arg(long, value_name = "path")]
198 pub write_default_conf: Option<PathBuf>,
199
200 #[cfg(unix)]
202 #[arg(long, value_name = "socket")]
203 pub send: Option<String>,
204
205 pub root: Option<PathBuf>,
207}
208
209#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
212pub enum TriBool {
213 Auto,
214 Yes,
215 No,
216}
217impl TriBool {
218 pub fn unwrap_or_else<F>(
219 self,
220 f: F,
221 ) -> bool
222 where
223 F: FnOnce() -> bool,
224 {
225 match self {
226 Self::Auto => f(),
227 Self::Yes => true,
228 Self::No => false,
229 }
230 }
231}
232
233#[derive(Debug, Clone, Copy, clap::ValueEnum)]
234pub enum CliShellInstallState {
235 Undefined, Refused,
237 Installed,
238}
239impl FromStr for CliShellInstallState {
240 type Err = String;
241 fn from_str(state: &str) -> Result<Self, Self::Err> {
242 match state {
243 "undefined" => Ok(Self::Undefined),
244 "refused" => Ok(Self::Refused),
245 "installed" => Ok(Self::Installed),
246 _ => Err(format!("unexpected install state: {state:?}")),
247 }
248 }
249}