getopt: indentation reduction

See the `git diff -w` output:
|diff --git a/src/getopts.rs b/src/getopts.rs
|index 6548a01..517cc37 100644
|--- a/src/getopts.rs
|+++ b/src/getopts.rs
|@@ -72,7 +72,10 @@ pub fn parse_arguments(
|     while pos < args.len() {
|         if skip {
|             rest.push(args[pos].clone());
|-        } else {
|+            pos += 1;
|+            continue;
|+        }
|+
|         match parse_argument(&args[pos]) {
|             RawArgument::Separator => {
|                 skip = true;
|@@ -135,7 +138,6 @@ pub fn parse_arguments(
|                 rest.push(value);
|             }
|         }
|-        }
|
|         pos += 1;
|     }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2018-12-28 13:54:18 +01:00
parent ad8a98f7e4
commit 99da3a073d
1 changed files with 56 additions and 54 deletions

View File

@ -72,68 +72,70 @@ pub fn parse_arguments(
while pos < args.len() {
if skip {
rest.push(args[pos].clone());
} else {
match parse_argument(&args[pos]) {
RawArgument::Separator => {
skip = true;
}
RawArgument::Option { name, value } => {
match value {
None => {
let mut want_bool = false;
let mut can_default = false;
if let Some((_optional, param_schema)) = properties.get::<str>(&name) {
if let Schema::Boolean(boolean_schema) = param_schema.as_ref() {
want_bool = true;
if let Some(default) = boolean_schema.default {
if default == false { can_default = true; }
} else {
can_default = true;
}
}
}
pos += 1;
continue;
}
let mut next_is_argument = false;
let mut next_is_bool = false;
if (pos + 1) < args.len() {
let next = &args[pos+1];
if let RawArgument::Argument { value: _} = parse_argument(next) {
next_is_argument = true;
if let Ok(_) = parse_boolean(next) { next_is_bool = true; }
}
}
if want_bool {
if next_is_bool {
pos += 1;
data.push((name, args[pos].clone()));
} else if can_default {
data.push((name, "true".to_string()));
match parse_argument(&args[pos]) {
RawArgument::Separator => {
skip = true;
}
RawArgument::Option { name, value } => {
match value {
None => {
let mut want_bool = false;
let mut can_default = false;
if let Some((_optional, param_schema)) = properties.get::<str>(&name) {
if let Schema::Boolean(boolean_schema) = param_schema.as_ref() {
want_bool = true;
if let Some(default) = boolean_schema.default {
if default == false { can_default = true; }
} else {
errors.push(format_err!("parameter '{}': {}", name,
"missing boolean value."));
}
} else {
if next_is_argument {
pos += 1;
data.push((name, args[pos].clone()));
} else {
errors.push(format_err!("parameter '{}': {}", name,
"missing parameter value."));
can_default = true;
}
}
}
Some(v) => {
data.push((name, v));
let mut next_is_argument = false;
let mut next_is_bool = false;
if (pos + 1) < args.len() {
let next = &args[pos+1];
if let RawArgument::Argument { value: _} = parse_argument(next) {
next_is_argument = true;
if let Ok(_) = parse_boolean(next) { next_is_bool = true; }
}
}
if want_bool {
if next_is_bool {
pos += 1;
data.push((name, args[pos].clone()));
} else if can_default {
data.push((name, "true".to_string()));
} else {
errors.push(format_err!("parameter '{}': {}", name,
"missing boolean value."));
}
} else {
if next_is_argument {
pos += 1;
data.push((name, args[pos].clone()));
} else {
errors.push(format_err!("parameter '{}': {}", name,
"missing parameter value."));
}
}
}
Some(v) => {
data.push((name, v));
}
}
RawArgument::Argument { value } => {
rest.push(value);
}
}
RawArgument::Argument { value } => {
rest.push(value);
}
}