From a9b6c2bd68ccfd72a833355fce55feda914fe3bd Mon Sep 17 00:00:00 2001 From: Luca Matei Pintilie Date: Wed, 13 Sep 2023 23:59:09 +0200 Subject: Add MMV_NAME and MCP_NAME compile-time variables Due to the sheer popularity of the "mmv" name it might conflict with other programs installed on the user's computer. As such the MMV_NAME and MCP_NAME environmental variables can control the program's name at compile time, allowing the user to avoid name conflicts with other programs. If the variables are not set then they will silently default back to "mmv" and "mcp" respectively. Signed-off-by: Luca Matei Pintilie Co-authored-by: Thomas Voss --- src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e8fb883..9885a82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,10 @@ use { tempfile::tempdir, }; + +const MMV_DEFAULT_NAME: &str = "mmv"; +const MCP_DEFAULT_NAME: &str = "mcp"; + struct Flags { pub backup: bool, pub dryrun: bool, @@ -54,7 +58,8 @@ impl Flags { let argv0 = env::args().next().unwrap(); let p = Path::new(&argv0).file_name().unwrap(); - if p == "mcp" { + let mcp_name = option_env!("MCP_NAME").unwrap_or(MCP_DEFAULT_NAME); + if p == mcp_name { flags.mcp = true; flags.backup = false; } @@ -85,7 +90,8 @@ fn usage(bad_flags: Option) -> ! { } let argv0 = env::args().next().unwrap(); let p = Path::new(&argv0).file_name().unwrap(); - if p == "mcp" { + let mcp_name = option_env!("MCP_NAME").unwrap_or(MCP_DEFAULT_NAME); + if p == mcp_name { eprintln!("Usage: {} [-0deiv] command [argument ...]", p.to_str().unwrap()); } else { eprintln!("Usage: {} [-0deinv] command [argument ...]", p.to_str().unwrap()); @@ -173,9 +179,10 @@ fn work() -> Result<(), io::Error> { let cache_base = env::var("XDG_CACHE_HOME").unwrap_or_else(|_| { err!("XDG_CACHE_HOME variable must be set"); }); + let mmv_name = option_env!("MMV_NAME").unwrap_or(MMV_DEFAULT_NAME); cache_dir = [ Path::new(cache_base.as_str()), - Path::new("mmv"), + Path::new(mmv_name), Path::new(ts.as_str()), ] .iter() -- cgit v1.2.3