summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index c3fd4ed..61d28c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,12 +7,14 @@ extern crate clap;
extern crate log;
use std::process::exit;
-use std::{env, fs, error};
+use std::{env, fs};
use clap::{App, Shell};
-use gitjournal::{GitJournal, error};
-fn error_and_exit(string: &str, error: Box<error::Error>) {
+use gitjournal::GitJournal;
+use gitjournal::errors::*;
+
+fn error_and_exit(string: &str, error: Error) {
error!("{}: {}", string, error);
exit(1);
}
@@ -35,12 +37,12 @@ fn main() {
}
}
-fn run() -> Result<(), Box<error::Error>> {
+fn run() -> Result<()> {
// Load the CLI parameters from the yaml file
let yaml = load_yaml!("cli.yaml");
let mut app = App::from_yaml(yaml).version(crate_version!());
let matches = app.clone().get_matches();
- let path = matches.value_of("path").ok_or_else(|| error("Cli", "No 'path' provided"))?;
+ let path = matches.value_of("path").ok_or_else(|| "No CLI 'path' provided")?;
// Create the journal
let mut journal = GitJournal::new(path)?;
@@ -50,7 +52,7 @@ fn run() -> Result<(), Box<error::Error>> {
Some("prepare") => {
// Prepare a commit message before editing by the user
if let Some(sub_matches) = matches.subcommand_matches("prepare") {
- match journal.prepare(sub_matches.value_of("message").ok_or_else(|| error("Cli", "No 'message' provided"))?,
+ match journal.prepare(sub_matches.value_of("message").ok_or_else(|| "No CLI 'message' provided")?,
sub_matches.value_of("type")) {
Ok(()) => info!("Commit message prepared."),
Err(error) => error_and_exit("Commit message preparation failed", error),
@@ -78,7 +80,7 @@ fn run() -> Result<(), Box<error::Error>> {
Some("verify") => {
// Verify a commit message
if let Some(sub_matches) = matches.subcommand_matches("verify") {
- match journal.verify(sub_matches.value_of("message").ok_or_else(|| error("Cli", "No 'message' provided"))?) {
+ match journal.verify(sub_matches.value_of("message").ok_or_else(|| "No CLI 'message' provided")?) {
Ok(()) => info!("Commit message valid."),
Err(error) => error_and_exit("Commit message invalid", error),
}
@@ -86,11 +88,10 @@ fn run() -> Result<(), Box<error::Error>> {
}
_ => {
// Get all values of the given CLI parameters with default values
- let revision_range = matches.value_of("revision_range")
- .ok_or_else(|| error("Cli", "No 'revision_range' provided"))?;
+ let revision_range = matches.value_of("revision_range").ok_or_else(|| "No CLI 'revision_range' provided")?;
let tag_skip_pattern = matches.value_of("tag_skip_pattern")
- .ok_or_else(|| error("Cli", "No 'task_skip_pattern' provided"))?;
- let tags_count = matches.value_of("tags_count").ok_or_else(|| error("Cli", "No 'tags_count' provided"))?;
+ .ok_or_else(|| "No CLI 'task_skip_pattern' provided")?;
+ let tags_count = matches.value_of("tags_count").ok_or_else(|| "No CLI 'tags_count' provided")?;
let max_tags = tags_count.parse::<u32>()?;
// Parse the log
@@ -107,8 +108,8 @@ fn run() -> Result<(), Box<error::Error>> {
journal.generate_template()?;
} else {
journal.print_log(matches.is_present("short"),
- matches.value_of("template"),
- matches.value_of("output"))?;
+ matches.value_of("template"),
+ matches.value_of("output"))?;
}
}
};