Skip to content

Commit bac70db

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

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/lib.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ use std::{
9494
path::{Path, PathBuf},
9595
sync::Arc,
9696
};
97+
use std::time::Instant;
9798

9899
use async_trait::async_trait;
99100
use clap::{Args, Command, CommandFactory, FromArgMatches as _, Parser, Subcommand};
@@ -678,21 +679,30 @@ impl Orogene {
678679
}
679680

680681
pub async fn load() -> Result<()> {
681-
let start = std::time::Instant::now();
682+
Self::init_and_run(Self::current_command(), std::env::args_os().collect::<Vec<_>>()).await
683+
}
684+
685+
pub async fn init_and_run(command: Command, args: Vec<OsString>) -> Result<()> {
686+
let start = Instant::now();
682687
// We have to instantiate Orogene twice: once to pick up "base" config
683688
// options, like `root` and `config`, which affect our overall config
684689
// parsing, and then a second time to pick up config options from the
685690
// config file(s). The first instantiation also ignores errors,
686691
// because what we really need to apply the negations to is the
687692
// 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()?;
693+
let matches = command.clone().get_matches_from(args.clone());
694+
let oro = Orogene::from_arg_matches(&matches).expect("Failed to match args");
691695
let config = oro.build_config()?;
692-
let mut args = std::env::args_os().collect::<Vec<_>>();
696+
Self::entry(start, oro, config, command, args).await
697+
}
698+
699+
pub async fn entry(
700+
start: Instant,
701+
mut oro: Orogene,
702+
config: OroConfig,
703+
command: Command,
704+
mut args: Vec<OsString>) -> Result<()> {
693705
Self::layer_command_args(&command, &mut args, &config)?;
694-
let mut oro =
695-
Orogene::from_arg_matches(&command.get_matches_from(&args)).into_diagnostic()?;
696706
let log_file = oro
697707
.cache
698708
.clone()

0 commit comments

Comments
 (0)