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
|
// Copyleft (ɔ) 2021-2021 Fuwn
// SPDX-License-Identifier: GPL-3.0-only
use structopt::{
clap,
clap::{App, Arg, SubCommand},
};
use crate::nitrous::Nitrous;
pub struct Cli;
impl Cli {
pub async fn execute() {
let matches = Self::cli().get_matches();
let mut debug = false;
if matches.is_present("debug") {
debug = true;
}
if matches.is_present("generate") {
Nitrous::generate(
matches
.subcommand_matches("generate")
.unwrap()
.value_of("amount")
.unwrap()
.to_string()
.parse::<usize>()
.unwrap(),
debug,
);
} else if matches.is_present("check") {
Nitrous::check(
matches
.subcommand_matches("check")
.unwrap()
.value_of("file")
.unwrap(),
debug,
)
.await;
}
}
fn cli() -> App<'static, 'static> {
App::new(env!("CARGO_PKG_NAME"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommands(vec![
SubCommand::with_name("generate").alias("gen").arg(
Arg::with_name("amount")
.required(true)
.index(1)
.takes_value(true),
),
SubCommand::with_name("check").arg(
Arg::with_name("file")
.required(true)
.takes_value(true)
.index(1),
),
])
.arg(Arg::with_name("debug")
.long("debug")
.short("d")
.takes_value(false)
.multiple(false)
.global(true)
)
}
}
|