Refactored parse_args loop
Thanks @PabloMansanet
This commit is contained in:
parent
7202953e69
commit
f0018280cb
1 changed files with 9 additions and 10 deletions
|
@ -60,19 +60,19 @@ fn parse_args(mut args: Args) -> Result<Args> {
|
||||||
|
|
||||||
iter.next(); // skip the program, we don't care about that
|
iter.next(); // skip the program, we don't care about that
|
||||||
|
|
||||||
loop {
|
while let Some(arg) = iter.next() {
|
||||||
match iter.next() {
|
match arg.as_str() {
|
||||||
Some(arg) if arg == "--" => break, // stop parsing at this point treat the remaining as files
|
"--" => break, // stop parsing at this point treat the remaining as files
|
||||||
Some(arg) if arg == "--version" => args.display_version = true,
|
"--version" => args.display_version = true,
|
||||||
Some(arg) if arg == "--help" => args.display_help = true,
|
"--help" => args.display_help = true,
|
||||||
Some(arg) if arg.starts_with("--") => {
|
arg if arg.starts_with("--") => {
|
||||||
return Err(Error::msg(format!(
|
return Err(Error::msg(format!(
|
||||||
"unexpected double dash argument: {}",
|
"unexpected double dash argument: {}",
|
||||||
arg
|
arg
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Some(arg) if arg.starts_with('-') => {
|
arg if arg.starts_with('-') => {
|
||||||
let arg = arg.as_str().get(1..).unwrap().chars();
|
let arg = arg.get(1..).unwrap().chars();
|
||||||
for chr in arg {
|
for chr in arg {
|
||||||
match chr {
|
match chr {
|
||||||
'v' => args.verbosity += 1,
|
'v' => args.verbosity += 1,
|
||||||
|
@ -82,8 +82,7 @@ fn parse_args(mut args: Args) -> Result<Args> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(arg) => args.files.push(PathBuf::from(arg)),
|
arg => args.files.push(PathBuf::from(arg)),
|
||||||
None => break, // No more arguments to reduce
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue