From b408f13ccec8124181d2075379a5f63ec1ef66b9 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:45:47 +0200 Subject: [PATCH] add --help, --version/-v --- README.md | 3 +++ src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b85286d..1011e10 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ - ```iw4-sp```, ```iw4x```, ```iw5-mod```, ```iw6-mod```, ```s1-mod``` - Skip automatic detection and launch the specified game + - This should always be the first argument if used - ```--update```, ```-u``` - Only update the game, don't launch it - ```--skip-launcher-update``` @@ -31,6 +32,8 @@ - Do not include a trailing backslash in the path - ```--pass``` - Pass additional arguments to the game +- ```--version```, ```-v``` + - Print the launcher version Example: ```alterware-launcher.exe iw4x --bonus -u --path "C:\Games\IW4x" --pass "-console"``` diff --git a/src/main.rs b/src/main.rs index b6dec7a..27bac04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -308,6 +308,43 @@ fn main() { let mut args: Vec = std::env::args().collect(); + if arg_bool(&args, "--help") { + println!("CLI Args:"); + println!(" : Specify the client to launch"); + println!(" --help: Display this help message"); + println!(" --version: Display the launcher version"); + println!(" --path/-p : Specify the game directory"); + println!(" --update/-u: Update only, don't launch the game"); + println!(" --bonus: Download bonus content"); + println!(" --force/-f: Force file hash recheck"); + println!(" --pass : Pass arguments to the game"); + println!(" --skip-launcher-update: Skip launcher self-update"); + println!( + "\nExample:\n alterware-launcher.exe iw4x --bonus --pass \"-console -nointro\"" + ); + std::process::exit(0); + } + + if arg_bool(&args, "--version") || arg_bool(&args, "-v") { + println!( + "{} v{}", + "AlterWare Launcher".bright_green(), + env!("CARGO_PKG_VERSION") + ); + println!("https://github.com/{}/{}", GH_OWNER, GH_REPO); + println!( + "\n{}{}{}{}{}{}{}", + "For ".on_black(), + "Alter".bright_blue().on_black().underline(), + "Ware".white().on_black().underline(), + ".dev".on_black().underline(), + " by ".on_black(), + "mxve".bright_magenta().on_black().underline(), + ".de".on_black().underline() + ); + std::process::exit(0); + } + let install_path: PathBuf; if let Some(path) = arg_value(&args, "--path") { install_path = PathBuf::from(path); @@ -347,10 +384,8 @@ fn main() { if let Some(pass) = arg_value(&args, "--pass") { cfg.args = pass; arg_remove_value(&mut args, "--pass"); - } else { - if cfg.args.is_empty() { - cfg.args = String::from(""); - } + } else if cfg.args.is_empty() { + cfg.args = String::from(""); } let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());