177 false, |
185 false, |
178 ) |
186 ) |
179 }); |
187 }); |
180 |
188 |
181 non_repo_config |
189 non_repo_config |
182 .load_cli_args_config(early_args.config) |
190 .load_cli_args(early_args.config, early_args.color) |
183 .unwrap_or_else(|error| { |
191 .unwrap_or_else(|error| { |
184 exit( |
192 exit( |
185 &initial_current_dir, |
193 &initial_current_dir, |
186 &Ui::new_infallible(&non_repo_config), |
194 &Ui::new_infallible(&non_repo_config), |
187 OnUnsupported::from_config(&non_repo_config), |
195 OnUnsupported::from_config(&non_repo_config), |
524 /// These arguments are still declared when we do use Clap later, so that Clap |
532 /// These arguments are still declared when we do use Clap later, so that Clap |
525 /// does not return an error for their presence. |
533 /// does not return an error for their presence. |
526 struct EarlyArgs { |
534 struct EarlyArgs { |
527 /// Values of all `--config` arguments. (Possibly none) |
535 /// Values of all `--config` arguments. (Possibly none) |
528 config: Vec<Vec<u8>>, |
536 config: Vec<Vec<u8>>, |
|
537 /// Value of all the `--color` argument, if any. |
|
538 color: Option<Vec<u8>>, |
529 /// Value of the `-R` or `--repository` argument, if any. |
539 /// Value of the `-R` or `--repository` argument, if any. |
530 repo: Option<Vec<u8>>, |
540 repo: Option<Vec<u8>>, |
531 /// Value of the `--cwd` argument, if any. |
541 /// Value of the `--cwd` argument, if any. |
532 cwd: Option<Vec<u8>>, |
542 cwd: Option<Vec<u8>>, |
533 } |
543 } |
534 |
544 |
535 impl EarlyArgs { |
545 impl EarlyArgs { |
536 fn parse(args: impl IntoIterator<Item = OsString>) -> Self { |
546 fn parse(args: impl IntoIterator<Item = OsString>) -> Self { |
537 let mut args = args.into_iter().map(get_bytes_from_os_str); |
547 let mut args = args.into_iter().map(get_bytes_from_os_str); |
538 let mut config = Vec::new(); |
548 let mut config = Vec::new(); |
|
549 let mut color = None; |
539 let mut repo = None; |
550 let mut repo = None; |
540 let mut cwd = None; |
551 let mut cwd = None; |
541 // Use `while let` instead of `for` so that we can also call |
552 // Use `while let` instead of `for` so that we can also call |
542 // `args.next()` inside the loop. |
553 // `args.next()` inside the loop. |
543 while let Some(arg) = args.next() { |
554 while let Some(arg) = args.next() { |
547 } |
558 } |
548 } else if let Some(value) = arg.drop_prefix(b"--config=") { |
559 } else if let Some(value) = arg.drop_prefix(b"--config=") { |
549 config.push(value.to_owned()) |
560 config.push(value.to_owned()) |
550 } |
561 } |
551 |
562 |
|
563 if arg == b"--color" { |
|
564 if let Some(value) = args.next() { |
|
565 color = Some(value) |
|
566 } |
|
567 } else if let Some(value) = arg.drop_prefix(b"--color=") { |
|
568 color = Some(value.to_owned()) |
|
569 } |
|
570 |
552 if arg == b"--cwd" { |
571 if arg == b"--cwd" { |
553 if let Some(value) = args.next() { |
572 if let Some(value) = args.next() { |
554 cwd = Some(value) |
573 cwd = Some(value) |
555 } |
574 } |
556 } else if let Some(value) = arg.drop_prefix(b"--cwd=") { |
575 } else if let Some(value) = arg.drop_prefix(b"--cwd=") { |
565 repo = Some(value.to_owned()) |
584 repo = Some(value.to_owned()) |
566 } else if let Some(value) = arg.drop_prefix(b"-R") { |
585 } else if let Some(value) = arg.drop_prefix(b"-R") { |
567 repo = Some(value.to_owned()) |
586 repo = Some(value.to_owned()) |
568 } |
587 } |
569 } |
588 } |
570 Self { config, repo, cwd } |
589 Self { |
|
590 config, |
|
591 color, |
|
592 repo, |
|
593 cwd, |
|
594 } |
571 } |
595 } |
572 } |
596 } |
573 |
597 |
574 /// What to do when encountering some unsupported feature. |
598 /// What to do when encountering some unsupported feature. |
575 /// |
599 /// |