prepend args with --, -, add short args
This commit is contained in:
parent
e1b76c8e04
commit
0b4c6325c7
17
README.md
17
README.md
@ -16,11 +16,18 @@
|
|||||||
|
|
||||||
#### Command line arguments
|
#### Command line arguments
|
||||||
|
|
||||||
- Passing ```iw4-sp```, ```iw4x```, ```iw5-mod```, ```iw6-mod``` or ```s1-mod``` as the first argument will skip automatic game detection
|
- ```iw4-sp```, ```iw4x```, ```iw5-mod```, ```iw6-mod```, ```s1-mod```
|
||||||
- Passing ```update``` will stop the launcher from launching the game
|
- Skip automatic detection and launch the specified game
|
||||||
- ```skip-launcher-update``` skips launcher self-update
|
- ```--update```, ```-u```
|
||||||
- ```bonus``` download bonus content
|
- Only update the game, don't launch it
|
||||||
- ```force``` forces file hash recheck
|
- ```--skip-launcher-update```
|
||||||
|
- Don't update the launcher
|
||||||
|
- ```--bonus```
|
||||||
|
- Download bonus content
|
||||||
|
- ```--force```, ```-f```
|
||||||
|
- Force file hash recheck
|
||||||
|
|
||||||
|
Example: ```alterware-launcher.exe iw4x --bonus -u```
|
||||||
|
|
||||||
Some arguments can be set in alterware-launcher.json, args generally override the values of the config.
|
Some arguments can be set in alterware-launcher.json, args generally override the values of the config.
|
||||||
|
|
||||||
|
52
src/main.rs
52
src/main.rs
@ -281,6 +281,26 @@ fn setup_env() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn arg_value(args: &[String], arg: &str) -> Option<String> {
|
||||||
|
let val = args.iter()
|
||||||
|
.position(|r| r == arg)
|
||||||
|
.map(|e| args[e + 1].clone());
|
||||||
|
if let Some(ref val) = val {
|
||||||
|
if val.starts_with('-') {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val
|
||||||
|
}
|
||||||
|
|
||||||
|
fn arg_bool(args: &[String], arg: &str) -> bool {
|
||||||
|
args.iter().any(|r| r == arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn arg_remove(args: &mut Vec<String>, arg: &str) {
|
||||||
|
args.iter().position(|r| r == arg).map(|e| args.remove(e));
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
setup_env();
|
setup_env();
|
||||||
@ -288,33 +308,27 @@ fn main() {
|
|||||||
let mut args: Vec<String> = std::env::args().collect();
|
let mut args: Vec<String> = std::env::args().collect();
|
||||||
let mut cfg = config::load(PathBuf::from("alterware-launcher.json"));
|
let mut cfg = config::load(PathBuf::from("alterware-launcher.json"));
|
||||||
|
|
||||||
if args.contains(&String::from("update")) {
|
if !arg_bool(&args, "--skip-launcher-update") && !cfg.skip_self_update {
|
||||||
cfg.update_only = true;
|
|
||||||
args.iter()
|
|
||||||
.position(|r| r == "update")
|
|
||||||
.map(|e| args.remove(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !args.contains(&String::from("skip-launcher-update")) && !cfg.skip_self_update {
|
|
||||||
self_update::run(cfg.update_only);
|
self_update::run(cfg.update_only);
|
||||||
} else {
|
} else {
|
||||||
args.iter()
|
arg_remove(&mut args, "--skip-launcher-update");
|
||||||
.position(|r| r == "skip-launcher-update")
|
|
||||||
.map(|e| args.remove(e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.contains(&String::from("bonus")) {
|
if arg_bool(&args, "--update") || arg_bool(&args, "-u") {
|
||||||
|
cfg.update_only = true;
|
||||||
|
arg_remove(&mut args, "--update");
|
||||||
|
arg_remove(&mut args, "-u");
|
||||||
|
}
|
||||||
|
|
||||||
|
if arg_bool(&args, "--bonus") {
|
||||||
cfg.download_bonus_content = true;
|
cfg.download_bonus_content = true;
|
||||||
args.iter()
|
arg_remove(&mut args, "--bonus");
|
||||||
.position(|r| r == "bonus")
|
|
||||||
.map(|e| args.remove(e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.contains(&String::from("force")) {
|
if arg_bool(&args, "--force") || arg_bool(&args, "-f") {
|
||||||
cfg.force_update = true;
|
cfg.force_update = true;
|
||||||
args.iter()
|
arg_remove(&mut args, "--force");
|
||||||
.position(|r| r == "force")
|
arg_remove(&mut args, "-f");
|
||||||
.map(|e| args.remove(e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
let games_json = http::get_body_string(format!("{}/games.json", MASTER).as_str());
|
||||||
|
Loading…
Reference in New Issue
Block a user