|
86 | 86 | //! [our contribution guide]: https://orogene.dev/CONTRIBUTING/ |
87 | 87 | //! [Apache 2.0 License]: https://github.com/orogene/orogene/blob/main/LICENSE |
88 | 88 |
|
| 89 | +use std::time::Instant; |
89 | 90 | use std::{ |
90 | 91 | borrow::Cow, |
91 | 92 | collections::VecDeque, |
@@ -678,21 +679,35 @@ impl Orogene { |
678 | 679 | } |
679 | 680 |
|
680 | 681 | pub async fn load() -> Result<()> { |
681 | | - let start = std::time::Instant::now(); |
| 682 | + Self::init_and_run( |
| 683 | + Self::current_command(), |
| 684 | + std::env::args_os().collect::<Vec<_>>(), |
| 685 | + ) |
| 686 | + .await |
| 687 | + } |
| 688 | + |
| 689 | + pub async fn init_and_run(command: Command, args: Vec<OsString>) -> Result<()> { |
| 690 | + let start = Instant::now(); |
682 | 691 | // We have to instantiate Orogene twice: once to pick up "base" config |
683 | 692 | // options, like `root` and `config`, which affect our overall config |
684 | 693 | // parsing, and then a second time to pick up config options from the |
685 | 694 | // config file(s). The first instantiation also ignores errors, |
686 | 695 | // because what we really need to apply the negations to is the |
687 | 696 | // subcommand we're interested in. |
688 | | - let command = Self::current_command(); |
689 | | - let matches = command.clone().get_matches(); |
690 | | - let oro = Orogene::from_arg_matches(&matches).into_diagnostic()?; |
| 697 | + let matches = command.clone().get_matches_from(args.clone()); |
| 698 | + let oro = Orogene::from_arg_matches(&matches).expect("Failed to match args"); |
691 | 699 | let config = oro.build_config()?; |
692 | | - let mut args = std::env::args_os().collect::<Vec<_>>(); |
| 700 | + Self::entry(start, oro, config, command, args).await |
| 701 | + } |
| 702 | + |
| 703 | + pub async fn entry( |
| 704 | + start: Instant, |
| 705 | + mut oro: Orogene, |
| 706 | + config: OroConfig, |
| 707 | + command: Command, |
| 708 | + mut args: Vec<OsString>, |
| 709 | + ) -> Result<()> { |
693 | 710 | Self::layer_command_args(&command, &mut args, &config)?; |
694 | | - let mut oro = |
695 | | - Orogene::from_arg_matches(&command.get_matches_from(&args)).into_diagnostic()?; |
696 | 711 | let log_file = oro |
697 | 712 | .cache |
698 | 713 | .clone() |
|
0 commit comments