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. 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" | "-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); } } }