aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-08-02 00:47:53 +0200
committerTeddy Wing2020-08-02 00:47:53 +0200
commit13710b49cc40c0e78eec9a94ce9b0ea8a09c3860 (patch)
tree0ded95e864a307ba733a9134f28df40273665873
parentdff81f7b84c279d7e00fe7a885743605a2ac5b7e (diff)
downloadgit-suggestion-13710b49cc40c0e78eec9a94ce9b0ea8a09c3860.tar.bz2
git-sugpatch: Print error and exit on `Config::get` error
Add `exitcode` to exit with an appropriate code. Add the `gseprintln` macro to wrap `eprintln!()`, prefixing the output with "error: ".
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin/git-sugpatch.rs12
-rw-r--r--src/error.rs8
4 files changed, 27 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4be1b47..f0130fe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index d0ce530..dccaa62 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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);
+ })
+}