diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs index 07768f0..e605439 100644 --- a/src/config.rs +++ b/src/config.rs @@ -28,17 +28,14 @@ pub enum Error { Git(#[from] git2::Error), } -pub struct Config<'a> { +pub struct Config { pub github_token: String, pub o_r: Result<OwnerRepo, owner_repo::Error>, pub suggestions: Vec<String>, - - opts: Options, - usage_brief: &'a str, } -impl<'a> Config<'a> { - pub fn get(args: &[String], usage_brief: &'a str) -> Result<Self, Error> { +impl Config { + pub fn get(args: &[String], usage_brief: &str) -> Result<Self, Error> { let mut opts = Options::new(); opts.optopt( @@ -58,7 +55,13 @@ impl<'a> Config<'a> { let opt_matches = opts.parse(&args[1..])?; if opt_matches.opt_present("h") { - print!("{}", opts.usage(&usage_brief)); + print_usage(&opts, usage_brief); + + process::exit(exitcode::USAGE); + } + + if opt_matches.free.is_empty() { + print_usage(&opts, usage_brief); process::exit(exitcode::USAGE); } @@ -73,16 +76,9 @@ impl<'a> Config<'a> { github_token: Self::github_token(&opt_matches, &git_config)?, o_r: o_r, suggestions: opt_matches.free, - - opts: opts, - usage_brief, }) } - pub fn print_usage(&self) { - print!("{}", self.opts.usage(&self.usage_brief)) - } - fn github_token( opt_matches: &getopts::Matches, git_config: &git2::Config, @@ -119,6 +115,10 @@ impl<'a> Config<'a> { } } +fn print_usage(opts: &Options, brief: &str) { + print!("{}", opts.usage(brief)); +} + fn git_config_key(key: &str) -> String { format!("{}.{}", GIT_CONFIG_PREFIX, key) } |