[snowpatch] [PATCH] args: Fix (-v | --version)

Russell Currey ruscur at russell.cc
Mon Jul 18 10:55:31 AEST 2016


I thought we got this by default with docopt but that's not true.  There
is a helper in docopt, though, which is nice.

Signed-off-by: Russell Currey <ruscur at russell.cc>
---
V2: compile time, add prefix
---
 src/main.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index 9bb2064..57fd5ad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -245,8 +245,11 @@ fn main() {
     }
     log_builder.init().unwrap();
 
+    let version = format!("{} version {}",
+        env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
+
     let args: Args = Docopt::new(USAGE)
-        .and_then(|d| d.decode())
+        .and_then(|d| d.version(Some(version)).decode())
         .unwrap_or_else(|e| e.exit());
 
     let settings = settings::parse(args.arg_config_file);
-- 
2.9.0



More information about the snowpatch mailing list