From adf1e64d23af1b428666dc94d4fee85be8807349 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Feb 2020 08:58:11 +0100 Subject: Use existing variable instead of hardcoding appname Signed-off-by: Matthias Beyer --- bin/core/imag/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index 41757929..ea62eb7b 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -201,7 +201,7 @@ fn main() -> Result<()> { commands .iter() .map(|command| { - match Command::new(format!("imag-{}", command)) + match Command::new(format!("{}-{}", appname, command)) .stdin(::std::process::Stdio::inherit()) .stdout(::std::process::Stdio::piped()) .stderr(::std::process::Stdio::inherit()) @@ -242,10 +242,10 @@ fn main() -> Result<()> { let subcommand = String::from(subcommand); let subcommand = aliases.get(&subcommand).cloned().unwrap_or(subcommand); - debug!("Calling 'imag-{}' with args: {:?}", subcommand, subcommand_args); + debug!("Calling '{}-{}' with args: {:?}", appname, subcommand, subcommand_args); // Create a Command, and pass it the gathered arguments - match Command::new(format!("imag-{}", subcommand)) + match Command::new(format!("{}-{}", appname, subcommand)) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) -- cgit v1.2.3 From a3227e0a947a7cc76b01b0365f962b3b6e2fea1e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Feb 2020 09:08:00 +0100 Subject: Get the program name from the name of the executable This enables us, during the development phase, to install in-development binaries as "imag-unstable-" (for example), so that we have "imag" as a release binary in PATH and "imag-unstable" as a development binary in PATH. The change also enables the "imag" binary itself (if it is named "imag-unstable" for example) to call imag-unstable subcommands, because it calls "-", for example "imag-unstable-diary" instead of "imag-diary". Signed-off-by: Matthias Beyer --- bin/core/imag/src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index ea62eb7b..d08f2191 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -142,12 +142,17 @@ fn get_commands() -> Result> { fn main() -> Result<()> { // Initialize the Runtime and build the CLI - let appname = "imag"; + let appname = ::std::env::current_exe()? + .file_name() + .ok_or_else(|| format_err!("Program is not a file. This is a BUG, please file me."))? + .to_str() + .ok_or_else(|| format_err!("Program name is not UTF8. Whut?"))? + .to_string(); let version = make_imag_version!(); let about = "imag - the PIM suite for the commandline"; let commands = get_commands()?; let helptext = help_text(commands.clone()); - let mut app = Runtime::get_default_cli_builder(appname, &version, about) + let mut app = Runtime::get_default_cli_builder(&appname, &version, about) .settings(&[AppSettings::AllowExternalSubcommands, AppSettings::ArgRequiredElseHelp]) .arg(Arg::with_name("version") .long("version") -- cgit v1.2.3