Skip to content

Commit

Permalink
Add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Jan 28, 2024
1 parent a8d9dfc commit 5ae5a60
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ fn inner_main() -> Result<(), Error> {
if arg == "-h" || arg == "--help" {
print_usage(io::stdout())?;
return Ok(());
} else if arg == "--version" || arg == "-V" || arg == "-v" {
print_version()?;
return Ok(());
} else if arg == "-O" || arg == "--stdout" {
force_stdout = true;
} else if arg == "-E" || arg == "--stderr" {
Expand Down Expand Up @@ -86,20 +89,33 @@ fn inner_main() -> Result<(), Error> {
Ok(())
}

fn get_version_number() -> &'static str {
env!("CARGO_PKG_VERSION")
}

fn print_usage(mut f: impl io::Write) -> io::Result<()> {
write!(
f,
"Usage: bp [FLAGS] [file]
Version {version}
Flags:
-h --help show usage information
-v --version show version number
-O --stdout print clipboard contents to stdout
-E --stderr print clipboard contents to stderr
-s --strip strip whitespace from the content\n"
-s --strip strip whitespace from the content\n",
version = get_version_number()
)?;
Ok(())
}

fn print_version() -> io::Result<()> {
writeln!(io::stdout(), "bp {}", get_version_number())?;
Ok(())
}

fn main() {
match inner_main() {
Ok(()) => (),
Expand Down

0 comments on commit 5ae5a60

Please sign in to comment.