//! Handle user CLI inputs use crate::{ constants::{NAME, VERSION}, settings::WindowMode, GameSettings, }; use clap::{App, Arg}; use std::path::PathBuf; /// Run CLI parser and parse options into GameSettings structure pub fn parse(settings: &mut GameSettings) { let app = App::new(NAME) .version(VERSION) .author("Bread Machine (Katharina Fey <kookie@spacekookie.de)") .about("Main game client - consider running the game via the launcher instead") .arg( Arg::with_name("assets") .required(true) .takes_value(true) .help("Specify the path to load assets from"), ) .arg( Arg::with_name("width") .short("w") .takes_value(true) .help("Set the desired game window width"), ) .arg( Arg::with_name("height") .short("h") .takes_value(true) .help("Set the desired game window height"), ) .arg( Arg::with_name("fullscreen") .short("f") .help("Specify if the game should run full screen"), ); let matches = app.get_matches(); if let Some(assets) = matches.value_of("assets") { settings.assets = Some(PathBuf::new().join(assets)); } if let Some(width) = matches.value_of("width") { settings.window.width = str::parse(width).unwrap(); } if let Some(height) = matches.value_of("height") { settings.window.height = str::parse(height).unwrap(); } if matches.is_present("fullscreen") { settings.window.window_mode = WindowMode::Fullscreen; } }