aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-07-13 15:06:41 +0100
committertslil <tslil@posteo.de>2026-07-13 21:21:21 +0100
commit3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 (patch)
treeba711eb220e39fe64388d370b16384a7bc84eaab /src/cli.rs
parente0241df8afde0483fc36cb2300b53127672486dc (diff)
Pure history
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
new file mode 100644
index 0000000..f1563b3
--- /dev/null
+++ b/src/cli.rs
@@ -0,0 +1,60 @@
+use std::env;
+
+#[derive(Debug, PartialEq)]
+pub enum Action {
+ NewConfig,
+ NewState,
+ DumpTrajectory,
+ DumpLearner,
+ DumpAlbums,
+ Run,
+}
+
+const NAME: &str = env!("CARGO_PKG_NAME");
+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-learner Dump learner weights as JSON to stdout.
+ --dump-albums Dump album list from state 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") | Some("-h") => {
+ print_help();
+ None
+ }
+ Some("--version") | Some("-V") | Some("-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-learner") => Some(Action::DumpLearner),
+ Some("--dump-albums") => Some(Action::DumpAlbums),
+ Some(unknown) => {
+ eprintln!("Unknown option: {unknown}");
+ std::process::exit(1);
+ }
+ }
+}