aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorLuca Matei Pintilie <luca@lucamatei.com> 2023-09-13 23:59:09 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-09-14 00:02:51 +0200
commita9b6c2bd68ccfd72a833355fce55feda914fe3bd (patch)
treefcfd937aac9dfc21034fee800b189e40fc902bdd /src/main.rs
parente93e75ca1dd782fb0c6df97be89d03d7f1cc66d3 (diff)
Add MMV_NAME and MCP_NAME compile-time variablesv1.3.0
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 <luca@lucamatei.com> Co-authored-by: Thomas Voss <mail@thomasvoss.com>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs13
1 files changed, 10 insertions, 3 deletions
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<lexopt::Error>) -> ! {
}
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()