1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
use {
std::{
path::PathBuf,
str::FromStr,
},
};
#[derive(Debug, clap::Parser)]
#[clap(author, version, about)]
pub struct Args {
#[clap(short, long, action)]
pub dates: bool,
#[clap(short='D', long, action)]
pub no_dates: bool,
#[clap(short='f', long, action)]
pub only_folders: bool,
#[clap(short='F', long, action)]
pub no_only_folders: bool,
#[clap(long, action)]
pub show_root_fs: bool,
#[clap(short='g', long, action)]
pub show_git_info: bool,
#[clap(short='G', long, action)]
pub no_show_git_info: bool,
#[clap(long, action)]
pub git_status: bool,
#[clap(short='h', long, action)]
pub hidden: bool,
#[clap(short='H', long, action)]
pub no_hidden: bool,
#[clap(short='i', long, action)]
pub git_ignored: bool,
#[clap(short='I', long, action)]
pub no_git_ignored: bool,
#[clap(short='p', long, action)]
pub permissions: bool,
#[clap(short='P', long, action)]
pub no_permissions: bool,
#[clap(short='s', long, action)]
pub sizes: bool,
#[clap(short='S', long, action)]
pub no_sizes: bool,
#[clap(long, action)]
pub sort_by_count: bool,
#[clap(long, action)]
pub sort_by_date: bool,
#[clap(long, action)]
pub sort_by_size: bool,
#[clap(long, action)]
pub sort_by_type: bool,
#[clap(long, action)]
pub sort_by_type_dirs_first: bool,
#[clap(long, action)]
pub sort_by_type_dirs_last: bool,
#[clap(short, long, action)]
pub whale_spotting: bool,
#[clap(long, action)]
pub no_sort: bool,
#[clap(short='t', long, action)]
pub trim_root: bool,
#[clap(short='T', long, action)]
pub no_trim_root: bool,
#[clap(long, value_parser)]
pub outcmd: Option<PathBuf>,
#[clap(short, long, value_parser)]
pub cmd: Option<String>,
#[clap(long, arg_enum, value_parser, default_value="auto")]
pub color: TriBool,
#[clap(long, value_parser)]
pub conf: Option<String>,
#[clap(long, value_parser)]
pub height: Option<u16>,
#[clap(long, action)]
pub install: bool,
#[clap(long, value_parser)]
pub set_install_state: Option<ShellInstallState>,
#[clap(long, value_parser)]
pub print_shell_function: Option<String>,
#[cfg(unix)]
#[clap(long, value_parser)]
pub listen: Option<String>,
#[cfg(unix)]
#[clap(long, action)]
pub get_root: bool,
#[clap(long, value_parser)]
pub write_default_conf: Option<PathBuf>,
#[cfg(unix)]
#[clap(long, value_parser)]
pub send: Option<String>,
#[clap(value_parser, value_name="FILE")]
pub root: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ArgEnum)]
pub enum TriBool {
Auto,
Yes,
No,
}
impl TriBool {
pub fn unwrap_or_else<F>(self, f: F) -> bool
where
F: FnOnce() -> bool
{
match self {
Self::Auto => f(),
Self::Yes => true,
Self::No => false,
}
}
}
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum ShellInstallState {
Undefined, Refused,
Installed,
}
impl FromStr for ShellInstallState {
type Err = String;
fn from_str(state: &str) -> Result<Self, Self::Err> {
match state {
"undefined" => Ok(Self::Undefined),
"refused" => Ok(Self::Refused),
"installed" => Ok(Self::Installed),
_ => Err(
format!("unexpected install state: {:?}", state)
),
}
}
}