diff --git a/src/Rust/src/commands/mod.rs b/src/Rust/src/commands/mod.rs index 83273075..3dfac135 100644 --- a/src/Rust/src/commands/mod.rs +++ b/src/Rust/src/commands/mod.rs @@ -1,7 +1,9 @@ mod apply; pub use apply::*; +#[cfg(target_os = "windows")] mod start; +#[cfg(target_os = "windows")] pub use start::*; #[cfg(target_os = "windows")] diff --git a/src/Rust/src/commands/start.rs b/src/Rust/src/commands/start.rs index 42e701df..0f8714e3 100644 --- a/src/Rust/src/commands/start.rs +++ b/src/Rust/src/commands/start.rs @@ -1,8 +1,8 @@ use crate::shared; use anyhow::{bail, Result}; +use std::path::Path; -#[cfg(target_os = "windows")] -pub fn start(wait_for_parent: bool, exe_args: Option>, legacy_args: Option<&String>) -> Result<()> { +pub fn start(wait_for_parent: bool, exe_name: Option<&String>, exe_args: Option>, legacy_args: Option<&String>) -> Result<()> { if legacy_args.is_some() && exe_args.is_some() { bail!("Cannot use both legacy args and new args format."); } @@ -14,8 +14,12 @@ pub fn start(wait_for_parent: bool, exe_args: Option>, legacy_args: Op let (root_path, app) = shared::detect_current_manifest()?; let current = app.get_current_path(&root_path); - let exe = app.get_main_exe_path(&root_path); - let exe_to_execute = std::path::Path::new(&exe); + let exe_to_execute = if let Some(exe) = exe_name { + Path::new(¤t).join(exe) + } else { + let exe = app.get_main_exe_path(&root_path); + Path::new(&exe).to_path_buf() + }; if !exe_to_execute.exists() { bail!("Unable to find executable to start: '{}'", exe_to_execute.to_string_lossy()); @@ -35,12 +39,3 @@ pub fn start(wait_for_parent: bool, exe_args: Option>, legacy_args: Op Ok(()) } - -#[cfg(target_os = "macos")] -pub fn start(wait_for_parent: bool, exe_args: Option>, legacy_args: Option<&String>) -> Result<()> { - if wait_for_parent { - shared::wait_for_parent_to_exit(60_000)?; // 1 minute - } - let (root_path, app) = shared::detect_current_manifest()?; - shared::start_package(&app, &root_path, exe_args) -} diff --git a/src/Rust/src/update.rs b/src/Rust/src/update.rs index 0c63bd46..2e3fb8f0 100644 --- a/src/Rust/src/update.rs +++ b/src/Rust/src/update.rs @@ -30,13 +30,6 @@ fn root_command() -> Command { .arg(arg!(-p --package "Update package to apply").value_parser(value_parser!(PathBuf))) .arg(arg!([EXE_ARGS] "Arguments to pass to the started executable. Must be preceeded by '--'.").required(false).last(true).num_args(0..)) ) - .subcommand(Command::new("start") - .about("Starts the currently installed version of the application") - .arg(arg!(-a --args "Legacy args format").aliases(vec!["processStartArgs", "process-start-args"]).hide(true).allow_hyphen_values(true).num_args(1)) - .arg(arg!(-w --wait "Wait for the parent process to terminate before starting the application")) - .arg(arg!([EXE_ARGS] "Arguments to pass to the started executable. Must be preceeded by '--'.").required(false).last(true).num_args(0..)) - .long_flag_aliases(vec!["processStart", "processStartAndWait"]) - ) .arg(arg!(--verbose "Print debug messages to console / log").global(true)) .arg(arg!(--nocolor "Disable colored output").hide(true).global(true)) .arg(arg!(-s --silent "Don't show any prompts / dialogs").global(true)) @@ -44,6 +37,16 @@ fn root_command() -> Command { .disable_help_subcommand(true) .flatten_help(true); + #[cfg(target_os = "windows")] + let cmd = cmd.subcommand(Command::new("start") + .about("Starts the currently installed version of the application") + .arg(arg!(-a --args "Legacy args format").aliases(vec!["processStartArgs", "process-start-args"]).hide(true).allow_hyphen_values(true).num_args(1)) + .arg(arg!(-w --wait "Wait for the parent process to terminate before starting the application")) + .arg(arg!([EXE_NAME] "The optional name of the binary to execute")) + .arg(arg!([EXE_ARGS] "Arguments to pass to the started executable. Must be preceeded by '--'.").required(false).last(true).num_args(0..)) + .long_flag_aliases(vec!["processStart", "processStartAndWait"]) + ); + #[cfg(target_os = "windows")] let cmd = cmd.subcommand(Command::new("uninstall") .about("Remove all app shortcuts, files, and registry entries.") @@ -94,6 +97,7 @@ fn main() -> Result<()> { let result = match subcommand { #[cfg(target_os = "windows")] "uninstall" => uninstall(subcommand_matches, log_file).map_err(|e| anyhow!("Uninstall error: {}", e)), + #[cfg(target_os = "windows")] "start" => start(&subcommand_matches).map_err(|e| anyhow!("Start error: {}", e)), "apply" => apply(subcommand_matches).map_err(|e| anyhow!("Apply error: {}", e)), _ => bail!("Unknown subcommand. Try `--help` for more information."), @@ -107,22 +111,6 @@ fn main() -> Result<()> { Ok(()) } -fn start(matches: &ArgMatches) -> Result<()> { - let legacy_args = matches.get_one::("args"); - let wait_for_parent = matches.get_flag("wait"); - let exe_args: Option> = matches.get_many::("EXE_ARGS").map(|v| v.map(|f| f.as_str()).collect()); - - info!("Command: Start"); - info!(" Wait: {:?}", wait_for_parent); - info!(" Exe Args: {:?}", exe_args); - if legacy_args.is_some() { - info!(" Legacy Args: {:?}", legacy_args); - warn!("Legacy args format is deprecated and will be removed in a future release. Please update your application to use the new format."); - } - - commands::start(wait_for_parent, exe_args, legacy_args) -} - fn apply(matches: &ArgMatches) -> Result<()> { let restart = matches.get_flag("restart"); let wait_for_parent = matches.get_flag("wait"); @@ -138,6 +126,25 @@ fn apply(matches: &ArgMatches) -> Result<()> { commands::apply(restart, wait_for_parent, package, exe_args) } +#[cfg(target_os = "windows")] +fn start(matches: &ArgMatches) -> Result<()> { + let legacy_args = matches.get_one::("args"); + let wait_for_parent = matches.get_flag("wait"); + let exe_name = matches.get_one::("EXE_NAME"); + let exe_args: Option> = matches.get_many::("EXE_ARGS").map(|v| v.map(|f| f.as_str()).collect()); + + info!("Command: Start"); + info!(" Wait: {:?}", wait_for_parent); + info!(" Exe Name: {:?}", exe_name); + info!(" Exe Args: {:?}", exe_args); + if legacy_args.is_some() { + info!(" Legacy Args: {:?}", legacy_args); + warn!("Legacy args format is deprecated and will be removed in a future release. Please update your application to use the new format."); + } + + commands::start(wait_for_parent, exe_name, exe_args, legacy_args) +} + #[cfg(target_os = "windows")] fn uninstall(_matches: &ArgMatches, log_file: &PathBuf) -> Result<()> { info!("Command: Uninstall");