From 5ba5612b2049be392c8eaaac1198e509660dae3a Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 12 Oct 2016 00:28:08 -0700 Subject: add version flags and command --- src/bin/einhyrningsinsctl.rs | 8 +++++++- src/main.rs | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bin/einhyrningsinsctl.rs b/src/bin/einhyrningsinsctl.rs index c057b9e..0e55073 100644 --- a/src/bin/einhyrningsinsctl.rs +++ b/src/bin/einhyrningsinsctl.rs @@ -108,17 +108,23 @@ fn main() { let mut opts = Options::new(); opts.optflag("h", "help", "print this help menu"); + opts.optflag("", "version", "print the version"); let matches = match opts.parse(&args[1..]) { Ok(m) => { m } Err(f) => { println!("{}", f.to_string()); print_usage(opts); exit(-1); } }; - if matches.opt_present("h") { + if matches.opt_present("help") { print_usage(opts); return; } + if matches.opt_present("version") { + println!("einhyrningsinsctl {}", env!("CARGO_PKG_VERSION")); + return; + } + // Bind to Control Socket let ctrl_path = Path::new("/tmp/einhorn.sock"); // XXX: handle this more gracefully (per-process) diff --git a/src/main.rs b/src/main.rs index 725cdbd..8699433 100644 --- a/src/main.rs +++ b/src/main.rs @@ -371,6 +371,7 @@ fn main() { let mut opts = Options::new(); opts.parsing_style(getopts::ParsingStyle::StopAtFirstFree); opts.optflag("h", "help", "print this help menu"); + opts.optflag("", "version", "print the version"); opts.optflag("v", "verbose", "more debugging messages"); opts.optflag("4", "ipv4-only", "only accept IPv4 connections"); opts.optflag("6", "ipv6-only", "only accept IPv6 connections"); @@ -383,11 +384,16 @@ fn main() { Err(f) => { println!("{}", f.to_string()); print_usage(opts); exit(-1); } }; - if matches.opt_present("h") { + if matches.opt_present("help") { print_usage(opts); return; } + if matches.opt_present("version") { + println!("einhyrningsins {}", env!("CARGO_PKG_VERSION")); + return; + } + if matches.opt_present("4") && matches.opt_present("6") { println!("Can't be both IPv4-only and IPv6-only"); exit(-1); @@ -562,6 +568,12 @@ fn ctrl_socket_handle(stream: UnixStream, ctrl_req_tx: Sender) { writer.flush().unwrap(); continue; }, + Some("version") => { + let ver = format!("\"einhyrningsinsctl {}\"\n", env!("CARGO_PKG_VERSION")); + writer.write_all(ver.as_bytes()).unwrap(); + writer.flush().unwrap(); + continue; + }, Some(_) | None => { writer.write_all("\"Missing or unhandled 'command'\"\n".as_bytes()).unwrap(); writer.flush().unwrap(); -- cgit v1.2.3