blob: 62ffd451a8ee68206b76896e58e3b4b8e9222624 (
plain)
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
|
mod exercises;
mod inflection;
mod init;
mod locale;
mod nuke;
mod run;
mod words;
/// Version for this program.
const VERSION: &str = "0.1.0";
fn help() {
println!("Self-assessment tool for language learning.\n");
println!("usage: mihi [OPTIONS] [COMMAND] [COMMAND OPTIONS]\n");
println!("Options:");
println!(" -h, --help\t\tPrint this message.");
println!(" -v, --version\tPrint the version of this program.\n");
println!("Commands:");
println!(" init\t\t\tInitialize the configuration for this application.");
println!(" nuke\t\t\tRemove all files from this application and its database.");
println!(" practice\t\tPractice vocabulary/exercises. Default command if none was given.");
println!(" words\t\tManage the words for this application.");
}
fn main() {
let mut args = std::env::args();
let nargs = args.len();
// Skip command name.
args.next();
match args.next() {
Some(command_flag) => match command_flag.as_str() {
"-h" | "--help" => {
if nargs > 2 {
println!("warning: arguments passed the 'help' flag will be ignored.\n");
}
help();
std::process::exit(0);
}
"-v" | "--version" => {
if nargs > 2 {
println!("warning: arguments passed the 'version' flag will be ignored.\n");
}
println!("mihi {VERSION}");
std::process::exit(0);
}
"init" => {
let rest: Vec<String> = args.collect();
init::run(rest);
}
"exercises" => {
let rest: Vec<String> = args.collect();
exercises::run(rest);
}
"nuke" => {
let rest: Vec<String> = args.collect();
nuke::run(rest);
}
"words" => {
let rest: Vec<String> = args.collect();
words::run(rest);
}
"practice" => {
let rest: Vec<String> = args.collect();
run::run(rest);
}
_ => {
println!("error: unknown flag or command: '{command_flag}'");
std::process::exit(1);
}
},
None => run::run(Vec::new()),
}
}
|