From 3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 Mon Sep 17 00:00:00 2001 From: tslil Date: Mon, 13 Jul 2026 15:06:41 +0100 Subject: Pure history --- src/cli.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/cli.rs (limited to 'src/cli.rs') 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. + Suggest and play the next album" + ); +} + +pub fn parse() -> Option { + 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); + } + } +} -- cgit v1.2.3