Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Make start a windows only command for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 25, 2023
1 parent d2a6398 commit 20e6d01
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/Rust/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
21 changes: 8 additions & 13 deletions src/Rust/src/commands/start.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<&str>>, legacy_args: Option<&String>) -> Result<()> {
pub fn start(wait_for_parent: bool, exe_name: Option<&String>, exe_args: Option<Vec<&str>>, legacy_args: Option<&String>) -> Result<()> {
if legacy_args.is_some() && exe_args.is_some() {
bail!("Cannot use both legacy args and new args format.");
}
Expand All @@ -14,8 +14,12 @@ pub fn start(wait_for_parent: bool, exe_args: Option<Vec<&str>>, 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(&current).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());
Expand All @@ -35,12 +39,3 @@ pub fn start(wait_for_parent: bool, exe_args: Option<Vec<&str>>, legacy_args: Op

Ok(())
}

#[cfg(target_os = "macos")]
pub fn start(wait_for_parent: bool, exe_args: Option<Vec<&str>>, 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)
}
51 changes: 29 additions & 22 deletions src/Rust/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ fn root_command() -> Command {
.arg(arg!(-p --package <FILE> "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 <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))
.arg(arg!(-l --log <PATH> "Override the default log file location").global(true).value_parser(value_parser!(PathBuf)))
.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 <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.")
Expand Down Expand Up @@ -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."),
Expand All @@ -107,35 +111,38 @@ fn main() -> Result<()> {
Ok(())
}

fn start(matches: &ArgMatches) -> Result<()> {
let legacy_args = matches.get_one::<String>("args");
fn apply(matches: &ArgMatches) -> Result<()> {
let restart = matches.get_flag("restart");
let wait_for_parent = matches.get_flag("wait");
let package = matches.get_one::<PathBuf>("package");
let exe_args: Option<Vec<&str>> = matches.get_many::<String>("EXE_ARGS").map(|v| v.map(|f| f.as_str()).collect());

info!("Command: Start");
info!("Command: Apply");
info!(" Restart: {:?}", restart);
info!(" Wait: {:?}", wait_for_parent);
info!(" Package: {:?}", package);
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)
commands::apply(restart, wait_for_parent, package, exe_args)
}

fn apply(matches: &ArgMatches) -> Result<()> {
let restart = matches.get_flag("restart");
#[cfg(target_os = "windows")]
fn start(matches: &ArgMatches) -> Result<()> {
let legacy_args = matches.get_one::<String>("args");
let wait_for_parent = matches.get_flag("wait");
let package = matches.get_one::<PathBuf>("package");
let exe_name = matches.get_one::<String>("EXE_NAME");
let exe_args: Option<Vec<&str>> = matches.get_many::<String>("EXE_ARGS").map(|v| v.map(|f| f.as_str()).collect());

info!("Command: Apply");
info!(" Restart: {:?}", restart);
info!("Command: Start");
info!(" Wait: {:?}", wait_for_parent);
info!(" Package: {:?}", package);
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::apply(restart, wait_for_parent, package, exe_args)
commands::start(wait_for_parent, exe_name, exe_args, legacy_args)
}

#[cfg(target_os = "windows")]
Expand Down

0 comments on commit 20e6d01

Please sign in to comment.