Skip to content

Commit acae64b

Browse files
committed
feat: add entrypoint for non-os args
Signed-off-by: Sam Gammon <[email protected]>
1 parent 2dc8d9e commit acae64b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
//! [our contribution guide]: https://orogene.dev/CONTRIBUTING/
8787
//! [Apache 2.0 License]: https://github.com/orogene/orogene/blob/main/LICENSE
8888
89+
use std::time::Instant;
8990
use std::{
9091
borrow::Cow,
9192
collections::VecDeque,
@@ -678,21 +679,35 @@ impl Orogene {
678679
}
679680

680681
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();
682691
// We have to instantiate Orogene twice: once to pick up "base" config
683692
// options, like `root` and `config`, which affect our overall config
684693
// parsing, and then a second time to pick up config options from the
685694
// config file(s). The first instantiation also ignores errors,
686695
// because what we really need to apply the negations to is the
687696
// 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");
691699
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<()> {
693710
Self::layer_command_args(&command, &mut args, &config)?;
694-
let mut oro =
695-
Orogene::from_arg_matches(&command.get_matches_from(&args)).into_diagnostic()?;
696711
let log_file = oro
697712
.cache
698713
.clone()

0 commit comments

Comments
 (0)