diff options
Diffstat (limited to 'src/cli.rs')
| -rw-r--r-- | src/cli.rs | 60 |
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); + } + } +} |
