diff options
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/bin/git-sugpatch.rs | 12 | ||||
-rw-r--r-- | src/error.rs | 8 |
4 files changed, 27 insertions, 1 deletions
@@ -174,6 +174,12 @@ dependencies = [ ] [[package]] +name = "exitcode" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" + +[[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -285,6 +291,7 @@ dependencies = [ name = "github-suggestion-cli" version = "0.0.1" dependencies = [ + "exitcode", "getopts", "git2", "github-suggestion", @@ -4,6 +4,7 @@ version = "0.0.1" edition = "2018" [dependencies] +exitcode = "1.1.2" getopts = "0.2.21" git2 = "0.13.8" regex = "1.3.9" diff --git a/src/bin/git-sugpatch.rs b/src/bin/git-sugpatch.rs index 04b687d..0159307 100644 --- a/src/bin/git-sugpatch.rs +++ b/src/bin/git-sugpatch.rs @@ -1,7 +1,10 @@ use std::env; use std::process; +use exitcode; + use github_suggestion::{Client, Suggestion, SuggestionUrl}; +use github_suggestion_cli::gseprintln; use github_suggestion_cli::config::Config; use github_suggestion_cli::error::Error; use github_suggestion_cli::is_suggestion_id; @@ -10,7 +13,14 @@ use github_suggestion_cli::is_suggestion_id; fn main() { let args: Vec<_> = env::args().collect(); - let config = Config::get(&args).unwrap(); + let config = match Config::get(&args) { + Ok(c) => c, + Err(e) => { + gseprintln!(e); + + process::exit(exitcode::DATAERR); + }, + }; if config.suggestions.is_empty() { process::exit(111); diff --git a/src/error.rs b/src/error.rs index c857bd2..bcca3e1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,3 +7,11 @@ pub enum Error { #[error("Unable to parse regex")] Regex(#[from] regex::Error), } + + +#[macro_export] +macro_rules! gseprintln { + ($arg:expr) => ({ + eprintln!("error: {}", $arg); + }) +} |