diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 4402014..476b597 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use std::env; +use std::process; use getopts::{self, Options}; use git2::{self, Repository}; @@ -27,23 +28,31 @@ pub enum Error { Git(#[from] git2::Error), } -pub struct Config { +pub struct Config<'a> { pub github_token: String, pub o_r: Result<OwnerRepo, owner_repo::Error>, pub suggestions: Vec<String>, opts: Options, + usage_brief: &'a str, } -impl Config { - pub fn get(args: &[String]) -> Result<Self, Error> { +impl<'a> Config<'a> { + pub fn get(args: &[String], usage_brief: &'a str) -> Result<Self, Error> { let mut opts = Options::new(); opts.optopt("", "github-token", "", "TOKEN"); opts.optopt("", "remote", "", "REMOTE"); + opts.optflag("h", "help", "print this help menu"); let opt_matches = opts.parse(&args[1..])?; + if opt_matches.opt_present("h") { + print!("{}", opts.usage(&usage_brief)); + + process::exit(exitcode::USAGE); + } + let git_config = Repository::open(".")?.config()?; let o_r = OwnerRepo::from_remote( @@ -56,11 +65,12 @@ impl Config { suggestions: opt_matches.free, opts: opts, + usage_brief, }) } - pub fn usage(&self, brief: &str) -> String { - self.opts.usage(&brief) + pub fn print_usage(&self) { + print!("{}", self.opts.usage(&self.usage_brief)) } fn github_token( |