Skip to content

Commit

Permalink
HOW COULD I FORGET THE VERSION STRING
Browse files Browse the repository at this point in the history
  • Loading branch information
perlisweird committed Aug 1, 2016
1 parent 7e8bb93 commit 7ef57c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frog_gopher"
version = "0.1.1"
version = "0.1.2"
authors = ["Perl I. W. <support@frog.tips>"]

[dependencies]
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mod cli {
use super::protocol::{ExternalAddr,ParseExternalAddrError};


const VERSION: &'static str = env!("CARGO_PKG_VERSION");

#[derive(Clone, Debug)]
pub struct Config {
pub int_addr: SocketAddr,
Expand All @@ -34,6 +36,7 @@ mod cli {
Usage(&'a str, Options),
BadOpt(Box<error::Error>),
MissingOpt(String),
Version,
}

impl<'a> From<AddrParseError> for Error<'a> {
Expand All @@ -58,6 +61,7 @@ mod cli {
opts.optopt("x", "ext-addr", "EXTERNAL ADDRESS.", "EXT_ADDR");
opts.optopt("k", "api-key", "YOUR FROG.TIPS API KEY.", "API_KEY");
opts.optflag("h", "help", "SHOW THIS HELP THEN EXIT.");
opts.optflag("v", "version", "SHOW THE CURRENT VERSION THEN EXIT.");

let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Expand All @@ -68,6 +72,10 @@ mod cli {
return Err(Error::Usage(program, opts));
}

if matches.opt_present("v") {
return Err(Error::Version);
}

let addr: SocketAddr = if !matches.free.is_empty() {
try!(matches.free[0].clone().parse())
} else {
Expand Down Expand Up @@ -97,6 +105,7 @@ mod cli {
Error::Usage(program, opts) => print_usage(&program, opts),
Error::BadOpt(err) => println!("ERROR: INVALID VALUE: '{}'.", err),
Error::MissingOpt(name) => println!("ERROR: {} IS REQUIRED.", name),
Error::Version => println!("{}, version {}", program, VERSION),
},
}
}
Expand Down

0 comments on commit 7ef57c7

Please sign in to comment.