diff --git a/shuffle3rs/Cargo.toml b/shuffle3rs/Cargo.toml index bda77e0..42101a2 100644 --- a/shuffle3rs/Cargo.toml +++ b/shuffle3rs/Cargo.toml @@ -15,14 +15,17 @@ opt-level = 1 opt-level = 1 [features] -default = ["deferred-drop"] +default = ["splash", "deferred-drop"] + +# Print name and info when printing help info +splash = [] # Move large objects to a seperate thread to be dropped. -deferred-drop = ["lazy_static"] +deferred-drop = [] [dependencies] cfg-if = "1.0.0" -lazy_static = {version = "1.4.0", optional = true} +lazy_static = "1.4.0" rand = "0.8.3" [dev-dependencies] diff --git a/shuffle3rs/src/arg.rs b/shuffle3rs/src/arg.rs new file mode 100644 index 0000000..82dd328 --- /dev/null +++ b/shuffle3rs/src/arg.rs @@ -0,0 +1,38 @@ + + +/// The executable program name +pub fn program_name() -> &'static str +{ + lazy_static! { + static ref NAME: String = std::env::args().next().unwrap(); + } + &NAME[..] +} + +#[cfg(feature="splash")] +#[inline] fn splash() +{ + println!("shuffle3rs (v{}) - improved 3 pass binary shuffler (Rust ver)", env!("CARGO_PKG_VERSION")); + println!(" written by {} with <3", env!("CARGO_PKG_AUTHORS")); + println!(" licensed with GPL v3.0 or later\n"); +} + +/// Print usage message +pub fn usage() +{ + #[cfg(feature="splash")] splash(); + + println!("Usage: {} -s ", program_name()); + println!("Usage: {} -u ", program_name()); + println!("\nOPTIONS:"); + println!(" -s\tShuffle file in place"); + println!(" -u\tUnshuffle file in place"); +} + +/// Print usage message and then exit with error code `2`. +#[inline] pub fn help() -> ! +{ + usage(); + + std::process::exit(2) +} diff --git a/shuffle3rs/src/main.rs b/shuffle3rs/src/main.rs index 756283f..6fba483 100644 --- a/shuffle3rs/src/main.rs +++ b/shuffle3rs/src/main.rs @@ -8,11 +8,11 @@ #[cfg(feature="deferred-drop")] mod defer_drop; mod shuffle; - +mod arg; fn main() { - println!("Hello, world!"); + arg::help(); } #[cfg(test)] mod test;