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
use {
crate::{
Key,
Fields,
},
argh::FromArgs,
std::path::PathBuf,
};
#[derive(Debug, Default, FromArgs)]
pub struct Args {
#[argh(switch)]
pub version: bool,
#[argh(option, default = "Default::default()")]
pub color: BoolArg,
#[argh(option, short = 'k', default = "Default::default()")]
pub key: Key,
#[argh(option, short = 'l', default = "1")]
pub length: usize,
#[argh(option, short = 'f', default = "Default::default()")]
pub fields: Fields,
#[argh(switch, short = 'c')]
pub changes: bool,
#[argh(option, short = 'd')]
pub date: Option<String>,
#[argh(option, short = 'i')]
pub ip: Option<String>,
#[argh(option, short = 'm')]
pub method: Option<String>,
#[argh(option, short = 'p')]
pub path: Option<String>,
#[argh(option, short = 'r')]
pub referer: Option<String>,
#[argh(option, short = 's')]
pub status: Option<String>,
#[argh(switch, short = 'a')]
pub all: bool,
#[argh(switch)]
pub no_name_check: bool,
#[argh(switch)]
pub lines: bool,
#[argh(switch)]
pub silent_load: bool,
#[argh(positional)]
pub file: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct BoolArg(Option<bool>);
impl BoolArg {
pub fn value(self) -> Option<bool> {
self.0
}
}
impl argh::FromArgValue for BoolArg {
fn from_arg_value(value: &str) -> Result<Self, String> {
match value.to_lowercase().as_ref() {
"auto" => Ok(BoolArg(None)),
"yes" => Ok(BoolArg(Some(true))),
"no" => Ok(BoolArg(Some(false))),
_ => Err(format!("Illegal value: {:?}", value)),
}
}
}