added version flag

This commit is contained in:
Valerie Wolfe 2024-02-04 16:11:32 -05:00
parent 2dd4e35600
commit 99531e785b
3 changed files with 16 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "remux" name = "remux"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -3,13 +3,14 @@ use std::process::exit;
use pico_args::Arguments; use pico_args::Arguments;
use crate::error; use crate::error;
use crate::VERSION;
pub fn help(pargs: &mut Arguments) { pub fn help(pargs: &mut Arguments) {
let topic = pargs.subcommand().unwrap(); let topic = pargs.subcommand().unwrap();
match topic.as_deref() { match topic.as_deref() {
None => { None => {
println!("remux v{}", env!("CARGO_PKG_VERSION")); println!("remux v{VERSION}");
println!("Valerie Wolfe <sleeplessval@gmail.com>"); println!("Valerie Wolfe <sleeplessval@gmail.com>");
println!("A command wrapper for tmux written in Rust.\n"); println!("A command wrapper for tmux written in Rust.\n");
@ -96,3 +97,7 @@ pub fn help(pargs: &mut Arguments) {
} }
} }
pub fn version() {
println!("remux v{VERSION}");
}

View file

@ -7,16 +7,24 @@ mod error;
mod help; mod help;
mod util; mod util;
use help::help; use help::{ help, version };
static VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() { fn main() {
let mut args = Arguments::from_env(); let mut args = Arguments::from_env();
if args.contains(["-h", "--help"]) { if args.contains(["-h", "--help"]) {
help(&mut args); help(&mut args);
return; return;
} }
if args.contains(["-v", "--version"]) {
version();
return;
}
if !stdout().is_terminal() { error::not_terminal(); } if !stdout().is_terminal() { error::not_terminal(); }
let subcommand = args.subcommand().unwrap(); let subcommand = args.subcommand().unwrap();