blob: 29ea2cfb6f1416cd87b08e2bfa6a6da10c1e9d60 (
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
|
use std::env;
#[derive(Debug, PartialEq)]
pub enum Action {
NewConfig,
NewState,
DumpTrajectory,
DumpIntuition,
Run,
}
const NAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
fn print_help() {
println!(
"\
{NAME}: {DESCRIPTION}
Usage: {NAME} [OPTION]
Options:
--help Show this help message.
--version Show version information.
--new-config Write a default config file and exit.
--new-state Write a default state file and exit.
--dump-trajectory Dump the play trajectory as JSON to stdout.
--dump-intuition Dump intuition data as JSON to stdout.
<no option> Suggest and play the next album"
);
}
pub fn parse() -> Option<Action> {
let mut args = env::args();
let _binary_name = args.next();
match args.next().as_deref() {
None => Some(Action::Run),
Some("--help" | "-h") => {
print_help();
None
}
Some("--version" | "-V" | "-v") => {
println!("{NAME} {VERSION}");
None
}
Some("--new-config") => Some(Action::NewConfig),
Some("--new-state") => Some(Action::NewState),
Some("--dump-trajectory") => Some(Action::DumpTrajectory),
Some("--dump-intuition") => Some(Action::DumpIntuition),
Some(unknown) => {
eprintln!("Unknown option: {unknown}");
std::process::exit(1);
}
}
}
|