Skip to content

Commit b0e65c1

Browse files
mmcamerasolve - accurately show the current executable file name
Because this executable gets renamed when it's installed in mmSolver and I don't want to hard-code any specific value in the executable.
1 parent 7a54d7d commit b0e65c1

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

  • lib/rust/mmcamerasolve-bin/src

lib/rust/mmcamerasolve-bin/src/cli.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
//
2020
//! CLI argument parsing without external dependencies.
2121
22+
use std::env;
23+
2224
use crate::parser;
2325

2426
use crate::defaults::DEFAULT_FILM_BACK_HEIGHT_MM;
@@ -182,12 +184,30 @@ impl Default for CliArgs {
182184
}
183185
}
184186

187+
fn default_executable_file_name() -> &'static str {
188+
match env::consts::OS {
189+
"windows" => "mmcamerasolve.exe",
190+
_ => "mmcamerasolve",
191+
}
192+
}
193+
194+
fn current_executable_file_name() -> String {
195+
match env::current_exe() {
196+
Ok(exe_path) => match exe_path.file_name() {
197+
Some(exe_file_name) => exe_file_name.to_string_lossy().to_string(),
198+
None => default_executable_file_name().to_string(),
199+
},
200+
Err(_) => default_executable_file_name().to_string(),
201+
}
202+
}
203+
185204
pub fn print_help() {
205+
let executable_name = current_executable_file_name();
186206
println!(
187207
"mmSolver Camera Solver - Structure from Motion camera solver.
188208
189209
USAGE:
190-
mmsfm <UV_FILE> [OPTIONS]
210+
{executable_name} <UV_FILE> [OPTIONS]
191211
192212
ARGUMENTS:
193213
<UV_FILE> Path to UV markers file (.uv)
@@ -244,7 +264,8 @@ HELP:
244264
}
245265

246266
pub fn print_version() {
247-
println!("mmsfm {}", env!("CARGO_PKG_VERSION"));
267+
let executable_name = current_executable_file_name();
268+
println!("{executable_name} {}", env!("CARGO_PKG_VERSION"));
248269
}
249270

250271
macro_rules! try_parse {

0 commit comments

Comments
 (0)