diff --git a/installer-gui/src-tauri/src/lib.rs b/installer-gui/src-tauri/src/lib.rs index 89fc561..fa74588 100644 --- a/installer-gui/src-tauri/src/lib.rs +++ b/installer-gui/src-tauri/src/lib.rs @@ -4,7 +4,7 @@ async fn run_installer(app_handle: tauri::AppHandle, args: String) -> anyhow::Re tauri::async_runtime::spawn_blocking(move || { installer::run_with_callback( // TODO: we should split using something similar to shlex in python - args.split_whitespace().map(String::from).collect(), + args.split_whitespace(), Some(Box::new(move |output| { app_handle .emit("installer-output", output) diff --git a/installer/src/lib.rs b/installer/src/lib.rs index df38892..a569c0a 100644 --- a/installer/src/lib.rs +++ b/installer/src/lib.rs @@ -285,34 +285,36 @@ async fn run(args: Args) -> Result<(), Error> { pub type OutputCallback = Box; /// Run the installer with CLI arguments and optional output callback +/// /// # Example /// ```no_run /// use installer; /// /// // if the callback is None, stdout/stderr is going to be used /// let result = installer::run_with_callback( -/// vec!["installer".to_string(), "orbic-network".to_string(), "--admin-password".to_string(), "12345".to_string()], +/// ["installer", "orbic-network", "--admin-password", "12345"], /// Some(Box::new(|output| { /// print!("{}", output); /// })) /// ); /// ``` -pub fn run_with_callback(args: Vec, callback: Option) -> Result<(), Error> { - // Set up the callback if provided +pub fn run_with_callback<'a>( + args: impl IntoIterator, + callback: Option, +) -> Result<(), Error> { let _guard; if let Some(cb) = callback { _guard = output::set_output_callback(move |s: &str| cb(s)); } - // Create a Tokio runtime and run the installer - tokio::runtime::Builder::new_current_thread() .enable_all() .build() .context("Failed to create Tokio runtime")? .block_on(async { // Parse arguments - let parsed_args = Args::try_parse_from(&args).context("Failed to parse arguments")?; + let parsed_args = + Args::try_parse_from(args.into_iter()).context("Failed to parse arguments")?; // Run the installer run(parsed_args).await