1use serde::Deserialize;
2use thiserror::Error;
3
4mod jc;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Command has no output")]
10 NoOutput,
11 #[error("Could not spawn jc. Please make sure it is installed")]
12 CouldNotSpawnJc(std::io::Error),
13
14 #[error("Command could not be spawned")]
15 CouldNotSpawnCommand,
16
17 #[error("Command output could not be parsed by jc")]
18 CouldNotParse,
19}
20
21pub enum CmdOutput {
23 Acpi,
24 Airport,
25 AirportS,
26 Arp,
27 Asciitable,
28 AsciitableM,
29 Blkid,
30 Cbt,
31 Cef,
32 CefS,
33 Chage,
34 Cksum,
35 Clf,
36 ClfS,
37 Crontab,
38 CrontabU,
39 Csv,
40 Custom(String),
41 Date,
42 Df,
43 Dig,
44 Dir,
45 Dmidecode,
46 DpkgL,
47 Du,
48 EmailAddress,
49 Env,
50 File,
51 Findmnt,
52 Finger,
53 Free,
54 Fstab,
55 GitLog,
56 GitLsRemote,
57 Gpg,
58 Group,
59 Gshadow,
60 Hash,
61 Hashsum,
62 Hciconfig,
63 Help,
64 History,
65 Hosts,
66 Id,
67 Ifconfig,
68 Ini,
69 Iostat,
70 IostatS,
71 IpAddress,
72 Iptables,
73 IsoDatetime,
74 Iwconfig,
75 IwScan,
76 JarManifest,
77 Jobs,
78 Jwt,
79 Kv,
80 Last,
81 Ls,
82 Lsblk,
83 Lsmod,
84 Lsof,
85 Lspci,
86 LsS,
87 Lsusb,
88 M3u,
89 Mdadm,
90 Mount,
91 Mpstat,
92 MpstatS,
93 Netstat,
94 Nmcli,
95 Ntpq,
96 Openvpn,
97 OsProber,
98 Passwd,
99 PciIds,
100 Pgpass,
101 Pidstat,
102 PidstatS,
103 Ping,
104 PingS,
105 PipList,
106 PipShow,
107 Plist,
108 Postconf,
109 Proc,
110 ProcCpuinfo,
111 ProcCrypto,
112 ProcDiskstats,
113 ProcInterrupts,
114 ProcLocks,
115 ProcModules,
116 ProcMtrr,
117 ProcNetDev,
118 ProcNetDevMcast,
119 ProcNetIgmp,
120 ProcNetIgmp6,
121 ProcNetNetlink,
122 ProcNetNetstat,
123 ProcNetPacket,
124 ProcNetProtocols,
125 ProcNetRoute,
126 ProcNetUnix,
127 ProcPartitions,
128 ProcPidMaps,
129 ProcPidMountinfo,
130 ProcPidNumaMaps,
131 ProcPidSmaps,
132 ProcPidStat,
133 ProcPidStatus,
134 ProcSwaps,
135 ProcVmallocinfo,
136 Ps,
137 Raw,
138 Route,
139 RpmQi,
140 Rsync,
141 Semver,
142 Sfdisk,
143 Shadow,
144 Ss,
145 SshdConf,
146 Stat,
147 StatS,
148 Sysctl,
149 Syslog,
150 SyslogBsd,
151 SyslogBsdS,
152 SyslogS,
153 Systemctl,
154 SystemctlLj,
155 SystemctlLs,
156 SystemctlLuf,
157 Systeminfo,
158 Time,
159 Timedatectl,
160 Timestamp,
161 Toml,
162 Top,
163 TopS,
164 Tracepath,
165 Traceroute,
166 Udevadm,
167 Ufw,
168 UfwAppinfo,
169 Uname,
170 UpdateAltGs,
171 UpdateAltQ,
172 Upower,
173 Uptime,
174 Url,
175 Vmstat,
176 VmstatS,
177 W,
178 Wc,
179 Who,
180 X509Cert,
181 Xml,
182 Xrandr,
183 Yaml,
184 Zipinfo,
185}
186
187impl CmdOutput {
188 pub(crate) fn get_flag(&self) -> &str {
189 match self {
190 Self::Acpi => "--acpi",
191 Self::Airport => "--airport",
192 Self::AirportS => "--airport-s",
193 Self::Arp => "--arp",
194 Self::Asciitable => "--asciitable",
195 Self::AsciitableM => "--asciitable-m",
196 Self::Blkid => "--blkid",
197 Self::Cbt => "--cbt",
198 Self::Cef => "--cef",
199 Self::CefS => "--cef-s",
200 Self::Chage => "--chage",
201 Self::Cksum => "--cksum",
202 Self::Clf => "--clf",
203 Self::ClfS => "--clf-s",
204 Self::Crontab => "--crontab",
205 Self::CrontabU => "--crontab-u",
206 Self::Csv => "--csv",
207 Self::Custom(string) => string,
208 Self::Date => "--date",
209 Self::Df => "--df",
210 Self::Dig => "--dig",
211 Self::Dir => "--dir",
212 Self::Dmidecode => "--dmidecode",
213 Self::DpkgL => "--dpkg-l",
214 Self::Du => "--du",
215 Self::EmailAddress => "--email-address",
216 Self::Env => "--env",
217 Self::File => "--file",
218 Self::Findmnt => "--findmnt",
219 Self::Finger => "--finger",
220 Self::Free => "--free",
221 Self::Fstab => "--fstab",
222 Self::GitLog => "--git-log",
223 Self::GitLsRemote => "--git-ls-remote",
224 Self::Gpg => "--gpg",
225 Self::Group => "--group",
226 Self::Gshadow => "--gshadow",
227 Self::Hash => "--hash",
228 Self::Hashsum => "--hashsum",
229 Self::Hciconfig => "--hciconfig",
230 Self::Help => "--help",
231 Self::History => "--history",
232 Self::Hosts => "--hosts",
233 Self::Id => "--id",
234 Self::Ifconfig => "--ifconfig",
235 Self::Ini => "--ini",
236 Self::Iostat => "--iostat",
237 Self::IostatS => "--iostat-s",
238 Self::IpAddress => "--ip-address",
239 Self::Iptables => "--iptables",
240 Self::IsoDatetime => "--iso-datetime",
241 Self::Iwconfig => "--iwconfig",
242 Self::IwScan => "--iw-scan",
243 Self::JarManifest => "--jar-manifest",
244 Self::Jobs => "--jobs",
245 Self::Jwt => "--jwt",
246 Self::Kv => "--kv",
247 Self::Last => "--last",
248 Self::Ls => "--ls",
249 Self::Lsblk => "--lsblk",
250 Self::Lsmod => "--lsmod",
251 Self::Lsof => "--lsof",
252 Self::Lspci => "--lspci",
253 Self::LsS => "--ls-s",
254 Self::Lsusb => "--lsusb",
255 Self::M3u => "--m3u",
256 Self::Mdadm => "--mdadm",
257 Self::Mount => "--mount",
258 Self::Mpstat => "--mpstat",
259 Self::MpstatS => "--mpstat-s",
260 Self::Netstat => "--netstat",
261 Self::Nmcli => "--nmcli",
262 Self::Ntpq => "--ntpq",
263 Self::Openvpn => "--openvpn",
264 Self::OsProber => "--os-prober",
265 Self::Passwd => "--passwd",
266 Self::PciIds => "--pci-ids",
267 Self::Pgpass => "--pgpass",
268 Self::Pidstat => "--pidstat",
269 Self::PidstatS => "--pidstat-s",
270 Self::Ping => "--ping",
271 Self::PingS => "--ping-s",
272 Self::PipList => "--pip-list",
273 Self::PipShow => "--pip-show",
274 Self::Plist => "--plist",
275 Self::Postconf => "--postconf",
276 Self::Proc => "--proc",
277 Self::ProcCpuinfo => "--proc_cpuinfo",
278 Self::ProcCrypto => "--proc_crypto",
279 Self::ProcDiskstats => "--proc_diskstats",
280 Self::ProcInterrupts => "--proc-interrupts",
281 Self::ProcLocks => "--proc-locks",
282 Self::ProcModules => "--proc-modules",
283 Self::ProcMtrr => "--proc-mtrr",
284 Self::ProcNetDev => "--proc-net-dev",
285 Self::ProcNetDevMcast => "--proc-net-dev-mcast",
286 Self::ProcNetIgmp => "--proc-net-igmp",
287 Self::ProcNetIgmp6 => "--proc-net-igmp6",
288 Self::ProcNetNetlink => "--proc-net-netlink",
289 Self::ProcNetNetstat => "--proc-net-netstat",
290 Self::ProcNetPacket => "--proc-net-packet",
291 Self::ProcNetProtocols => "--proc-net-protocols",
292 Self::ProcNetRoute => "--proc-net-route",
293 Self::ProcNetUnix => "--proc-net-unix",
294 Self::ProcPartitions => "--proc-partitions",
295 Self::ProcPidMaps => "--proc-pid-maps",
296 Self::ProcPidMountinfo => "--proc-pid-mountinfo",
297 Self::ProcPidNumaMaps => "--proc-pid-numa-maps",
298 Self::ProcPidSmaps => "--proc-pid-smaps",
299 Self::ProcPidStat => "--proc-pid-stat",
300 Self::ProcPidStatus => "--proc-pid-status",
301 Self::ProcSwaps => "--proc-swaps",
302 Self::ProcVmallocinfo => "--proc-vmallocinfo",
303 Self::Ps => "--ps",
304 Self::Raw => "--raw`",
305 Self::Route => "--route",
306 Self::RpmQi => "--rpm-qi",
307 Self::Rsync => "--rsync",
308 Self::Semver => "--semver",
309 Self::Sfdisk => "--sfdisk",
310 Self::Shadow => "--shadow",
311 Self::Ss => "--ss",
312 Self::SshdConf => "--sshd-conf",
313 Self::Stat => "--stat",
314 Self::StatS => "--stat-s",
315 Self::Sysctl => "--sysctl",
316 Self::Syslog => "--syslog",
317 Self::SyslogBsd => "--syslog-bsd",
318 Self::SyslogBsdS => "--syslog-bsd-s",
319 Self::SyslogS => "--syslog-s",
320 Self::Systemctl => "--systemctl",
321 Self::SystemctlLj => "--systemctl-lj",
322 Self::SystemctlLs => "--systemctl-ls",
323 Self::SystemctlLuf => "--systemctl-luf",
324 Self::Systeminfo => "--systeminfo",
325 Self::Time => "--time",
326 Self::Timedatectl => "--timedatectl",
327 Self::Timestamp => "--timestamp",
328 Self::Toml => "--toml",
329 Self::Top => "--top",
330 Self::TopS => "--top-s",
331 Self::Tracepath => "--tracepath",
332 Self::Traceroute => "--traceroute",
333 Self::Udevadm => "--udevadm",
334 Self::Ufw => "--ufw",
335 Self::UfwAppinfo => "--ufw-appinfo",
336 Self::Uname => "--uname",
337 Self::UpdateAltGs => "--update-alt-gs",
338 Self::UpdateAltQ => "--update-alt-q",
339 Self::Upower => "--upower",
340 Self::Uptime => "--uptime",
341 Self::Url => "--url",
342 Self::Vmstat => "--vmstat",
343 Self::VmstatS => "--vmstat-s",
344 Self::W => "--w",
345 Self::Wc => "--wc",
346 Self::Who => "--who",
347 Self::X509Cert => "--x509-cert",
348 Self::Xml => "--xml",
349 Self::Xrandr => "--xrandr",
350 Self::Yaml => "--yaml",
351 Self::Zipinfo => "--zipinfo",
352 }
353 }
354}
355
356pub trait JcWrapper<T> where T: for<'a> Deserialize<'a> {
357 fn parse(&mut self, output_type: CmdOutput) -> Result<T, Error>;
358}