on master help sign in
Refactored parse_args loop

Thanks @PabloMansanet

commitf0018280cbd6427d8102ccae7ec8c48ac046f922 authorCorey Powell <mistdragon100@gmail.com> dateWed 2 Jun 2021, 14:24 (5 years ago) parent7202953
1 file changed+9−10
helix-term/src/main.rs+9−10
helix-term/src/main.rs+9−10
@@ -60,19 +60,19 @@ fn parse_args(mut args: Args) -> Result<Args> {
6060
6161 iter.next(); // skip the program, we don't care about that
6262
63− loop {
64− match iter.next() {
65− Some(arg) if arg == "--" => break, // stop parsing at this point treat the remaining as files
66− Some(arg) if arg == "--version" => args.display_version = true,
67− Some(arg) if arg == "--help" => args.display_help = true,
68− Some(arg) if arg.starts_with("--") => {
63+ while let Some(arg) = iter.next() {
64+ match arg.as_str() {
65+ "--" => break, // stop parsing at this point treat the remaining as files
66+ "--version" => args.display_version = true,
67+ "--help" => args.display_help = true,
68+ arg if arg.starts_with("--") => {
6969 return Err(Error::msg(format!(
7070 "unexpected double dash argument: {}",
7171 arg
7272 )))
7373 }
74− Some(arg) if arg.starts_with('-') => {
75− let arg = arg.as_str().get(1..).unwrap().chars();
74+ arg if arg.starts_with('-') => {
75+ let arg = arg.get(1..).unwrap().chars();
7676 for chr in arg {
7777 match chr {
7878 'v' => args.verbosity += 1,
@@ -82,8 +82,7 @@ fn parse_args(mut args: Args) -> Result<Args> {
8282 }
8383 }
8484 }
85− Some(arg) => args.files.push(PathBuf::from(arg)),
86− None => break, // No more arguments to reduce
85+ arg => args.files.push(PathBuf::from(arg)),
8786 }
8887 }
8988