diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-17 10:51:26 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-17 10:52:47 +0100 |
| commit | c593918dd9df53d12c4664677f50aacdba6cfbb1 (patch) | |
| tree | 0c84de3e7922793fb93f28a329e3d39a510431d9 /src/main.rs | |
| parent | 1ddc6a781ccc46c8b6fe8d4309347221e3f878ac (diff) | |
Update readme, add version command
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index c6201db..833c846 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,6 +77,10 @@ struct Arguments { image_type: ImageType, } +fn print_help() { + println!("Usage: wmap [-t|--type IMAGE_TYPE] [-s|--stage STAGE] [-o|--output OUTPUT_FILE] INPUT_FILE"); +} + fn parse_arguments() -> Result<Arguments, lexopt::Error> { use lexopt::prelude::*; @@ -102,7 +106,12 @@ fn parse_arguments() -> Result<Arguments, lexopt::Error> { input = Some(value.string()?); } Short('h') | Long("help") => { - println!("Usage: wmap [-t|--type=png|svg] [-o=OUTPUT_FILE] INPUT_FILE"); + print_help(); + std::process::exit(0); + } + Short('v') | Long("version") => { + let version = env!("CARGO_PKG_VERSION"); + println!("{version}"); std::process::exit(0); } _ => return Err(argument.unexpected()), @@ -123,7 +132,7 @@ fn parse_arguments() -> Result<Arguments, lexopt::Error> { }) } -fn main() -> IoResult<()> { +fn run() -> IoResult<()> { let arguments = parse_arguments().map_err(|_| IoError::other("Unable to parse arguments"))?; arguments.input.try_exists()?; @@ -141,3 +150,21 @@ fn main() -> IoResult<()> { write(arguments.output, image_data)?; Ok(()) } + +fn main() -> IoResult<()> { + let result = run(); + + if cfg!(debug_assertions) { + result + } else { + match result { + Ok(()) => Ok(()), + Err(e) => { + eprintln!("Error: {e}"); + eprintln!(); + print_help(); + std::process::exit(1); + } + } + } +} |