feat(tauri) CLI args additions (positional args, bool as value for args with takesValue=false) (#695)

This commit is contained in:
Lucas Fernandes Nogueira 2020-06-18 13:01:47 -03:00 committed by GitHub
parent 1f2ff7dc25
commit d299a2b94d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -19,7 +19,7 @@ export interface CliArg {
requiresIf?: [string, string]
requiredIf?: [string, string]
requireEquals?: boolean
global?: boolean
index?: number
}
export interface CliConfig {

View File

@ -76,7 +76,7 @@ fn map_matches<T: Cli + 'static>(config: &T, matches: &ArgMatches, cli_matches:
for arg in args {
let occurrences = matches.occurrences_of(arg.name.clone());
let value = if occurrences == 0 || !arg.takes_value.unwrap_or(false) {
Value::Null
Value::Bool(occurrences > 0)
} else if arg.multiple.unwrap_or(false) {
matches
.values_of(arg.name.clone())
@ -142,6 +142,7 @@ fn get_app<'a, T: Cli + 'static>(name: &str, about: Option<&'a String>, config:
clap_arg = bind_if_arg!(arg, clap_arg, requires_if);
clap_arg = bind_if_arg!(arg, clap_arg, required_if);
clap_arg = bind_value_arg!(arg, clap_arg, require_equals);
clap_arg = bind_value_arg!(arg, clap_arg, index);
app = app.arg(clap_arg);
}

View File

@ -95,6 +95,7 @@ pub struct CliArg {
pub requires_if: Option<Vec<String>>,
pub required_if: Option<Vec<String>>,
pub require_equals: Option<bool>,
pub index: Option<u64>,
}
#[derive(PartialEq, Deserialize, Debug)]