Improve API argument parsing and help information

This commit is contained in:
timvisee 2019-02-27 23:30:00 +01:00
parent af98e133dc
commit ea41cbdbc6
No known key found for this signature in database
GPG key ID: B8DB720BC383E172

View file

@ -22,6 +22,10 @@ impl CmdArg for ArgApi {
.hide_env_values(true)
.global(true)
.help("Server API version to use, '-' to lookup")
.long_help("Server API version to use, one of:\n\
2, 3: Firefox Send API versions\n\
auto, -: probe server to determine\
")
}
}
@ -36,7 +40,7 @@ impl<'a> CmdArgOption<'a> for ArgApi {
};
// Parse the lookup version string
if version.trim() == "-" {
if is_auto(version) {
return DesiredVersion::Lookup;
}
@ -50,3 +54,10 @@ impl<'a> CmdArgOption<'a> for ArgApi {
}
}
}
/// Check whether the given API version argument means we've to probe the server for the proper
/// version.
fn is_auto(arg: &str) -> bool {
let arg = arg.trim().to_lowercase();
arg == "a" || arg == "auto" || arg == "-"
}