diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | bin/core/imag-annotate/src/main.rs | 6 | ||||
-rw-r--r-- | bin/core/imag-edit/src/main.rs | 2 | ||||
-rw-r--r-- | bin/core/imag-gps/src/main.rs | 3 | ||||
-rw-r--r-- | bin/core/imag-grep/src/main.rs | 2 | ||||
-rw-r--r-- | bin/core/imag-init/src/main.rs | 2 | ||||
-rw-r--r-- | bin/core/imag-link/src/main.rs | 2 | ||||
-rw-r--r-- | bin/core/imag-ref/src/main.rs | 1 | ||||
-rw-r--r-- | bin/core/imag/src/main.rs | 30 | ||||
-rw-r--r-- | bin/domain/imag-contact/src/main.rs | 1 | ||||
-rw-r--r-- | bin/domain/imag-habit/src/main.rs | 1 | ||||
-rw-r--r-- | bin/domain/imag-log/src/main.rs | 1 | ||||
-rw-r--r-- | bin/domain/imag-log/src/ui.rs | 1 | ||||
-rw-r--r-- | lib/core/libimagerror/src/iter.rs | 41 | ||||
-rwxr-xr-x | scripts/license-headers-updated | 39 |
15 files changed, 109 insertions, 24 deletions
diff --git a/.travis.yml b/.travis.yml index 38efdf12..04a9f5a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ addons: script: - | + bash ./scripts/license-headers-updated || exit 1 cargo build --all --all-features -j 1 || exit 1 cargo test --all --all-features -j 1 || exit 1 diff --git a/bin/core/imag-annotate/src/main.rs b/bin/core/imag-annotate/src/main.rs index dc82edd5..4bdd9443 100644 --- a/bin/core/imag-annotate/src/main.rs +++ b/bin/core/imag-annotate/src/main.rs @@ -94,8 +94,6 @@ fn add(rt: &Runtime) { .map_err_trace_exit_unwrap(1) .edit_content(&rt) .map_err_trace_exit_unwrap(1); - - info!("Ok"); } fn remove(rt: &Runtime) { @@ -130,8 +128,6 @@ fn remove(rt: &Runtime) { } else { debug!("Not deleting annotation object"); } - - info!("Ok"); } fn list(rt: &Runtime) { @@ -163,8 +159,6 @@ fn list(rt: &Runtime) { .collect::<Vec<_>>(); } } - - info!("Ok"); } fn list_annotation<'a>(i: usize, a: FileLockEntry<'a>, with_text: bool) { diff --git a/bin/core/imag-edit/src/main.rs b/bin/core/imag-edit/src/main.rs index 3524359c..bf05e8eb 100644 --- a/bin/core/imag-edit/src/main.rs +++ b/bin/core/imag-edit/src/main.rs @@ -80,7 +80,5 @@ fn main() { let _ = entry .edit_content(&rt) .map_err_trace_exit_unwrap(1); - - info!("Ok"); } diff --git a/bin/core/imag-gps/src/main.rs b/bin/core/imag-gps/src/main.rs index 00a8d218..eda98a19 100644 --- a/bin/core/imag-gps/src/main.rs +++ b/bin/core/imag-gps/src/main.rs @@ -138,8 +138,6 @@ fn remove(rt: &Runtime) { if scmd.is_present("print-removed") { println!("{}", removed_value); } - - info!("Ok"); } fn get(rt: &Runtime) { @@ -166,6 +164,5 @@ fn get(rt: &Runtime) { }); println!("{}", value); - info!("Ok"); } diff --git a/bin/core/imag-grep/src/main.rs b/bin/core/imag-grep/src/main.rs index c6c2c59f..9da97ae0 100644 --- a/bin/core/imag-grep/src/main.rs +++ b/bin/core/imag-grep/src/main.rs @@ -84,7 +84,7 @@ fn main() { if opts.count { println!("{}", count); - } else { + } else if !opts.files_with_matches { println!("Processed {} files, {} matches, {} nonmatches", overall_count, count, diff --git a/bin/core/imag-init/src/main.rs b/bin/core/imag-init/src/main.rs index 035d1590..5c6b3e44 100644 --- a/bin/core/imag-init/src/main.rs +++ b/bin/core/imag-init/src/main.rs @@ -128,7 +128,7 @@ fn main() { let path_str = path.to_str().map(String::from).expect("Cannot convert path to string"); let worktree = format!("--work-tree={}", path_str); - let gitdir = format!("--git-dir={}", path_str); + let gitdir = format!("--git-dir={}/.git", path_str); { let output = Command::new("git") diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index fe2fc091..40155f96 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -149,8 +149,6 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) info!("Ok: {} -> {}", from, entry); } - - info!("Ok"); } fn remove_linking(rt: &Runtime) { diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs index e781eef1..3235d1ce 100644 --- a/bin/core/imag-ref/src/main.rs +++ b/bin/core/imag-ref/src/main.rs @@ -86,7 +86,6 @@ fn add(rt: &Runtime) { match RefStore::create(rt.store(), path, flags) { Ok(r) => { debug!("Reference created: {:?}", r); - info!("Ok"); }, Err(e) => { trace_error(&e); diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index b569b46d..19f5308b 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -86,10 +86,10 @@ fn help_text(cmds: Vec<String>) -> String { /// Returns the list of imag-* executables found in $PATH fn get_commands() -> Vec<String> { - match env::var("PATH") { + let mut v = match env::var("PATH") { Err(e) => { println!("PATH error: {:?}", e); - exit(1); + exit(1) }, Ok(path) => path @@ -109,8 +109,11 @@ fn get_commands() -> Vec<String> { .and_then(|s| s.splitn(2, "-").nth(1).map(String::from)) ) }) - .collect() - } + .collect::<Vec<String>>() + }; + + v.sort(); + v } @@ -121,7 +124,7 @@ fn main() { let about = "imag - the PIM suite for the commandline"; let commands = get_commands(); let helptext = help_text(commands.clone()); - let app = Runtime::get_default_cli_builder(appname, version, about) + let mut app = Runtime::get_default_cli_builder(appname, version, about) .settings(&[AppSettings::AllowExternalSubcommands, AppSettings::ArgRequiredElseHelp]) .arg(Arg::with_name("version") .long("version") @@ -137,6 +140,23 @@ fn main() { .help("Get the versions of the imag commands")) .subcommand(SubCommand::with_name("help").help("Show help")) .after_help(helptext.as_str()); + + let long_help = { + let mut v = vec![]; + if let Err(e) = app.write_long_help(&mut v) { + eprintln!("Error: {:?}", e); + exit(1); + } + String::from_utf8(v).unwrap_or_else(|_| { eprintln!("UTF8 Error"); exit(1) }) + }; + { + let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false); + if print_help { + println!("{}", long_help); + exit(0) + } + } + let rt = Runtime::new(app) .unwrap_or_else(|e| { println!("Runtime couldn't be setup. Exiting"); diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs index 68c920b7..a6c3455d 100644 --- a/bin/domain/imag-contact/src/main.rs +++ b/bin/domain/imag-contact/src/main.rs @@ -196,7 +196,6 @@ fn show(rt: &Runtime) { let s = show_format.render("format", &data).map_err_trace_exit_unwrap(1); println!("{}", s); - info!("Ok"); } fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: &ArgMatches) -> Handlebars { diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs index 6960107a..f8fd12e3 100644 --- a/bin/domain/imag-habit/src/main.rs +++ b/bin/domain/imag-habit/src/main.rs @@ -136,7 +136,6 @@ fn create(rt: &Runtime) { }; hb.build(rt.store()).map_err_trace_exit_unwrap(1); - info!("Ok"); } fn delete(rt: &Runtime) { diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs index 40a29faa..cf2e4c97 100644 --- a/bin/domain/imag-log/src/main.rs +++ b/bin/domain/imag-log/src/main.rs @@ -87,7 +87,6 @@ fn main() { *fle.get_content_mut() = text; }) .map_err_trace_exit_unwrap(1); - info!("Ok"); } } diff --git a/bin/domain/imag-log/src/ui.rs b/bin/domain/imag-log/src/ui.rs index ea4786b5..a233e914 100644 --- a/bin/domain/imag-log/src/ui.rs +++ b/bin/domain/imag-log/src/ui.rs @@ -39,6 +39,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .subcommand(SubCommand::with_name("show") .about("View log(s)") .version("0.1") + .alias("list") .arg(Arg::with_name("show-all") .long("all") diff --git a/lib/core/libimagerror/src/iter.rs b/lib/core/libimagerror/src/iter.rs index 5058c941..07b15f67 100644 --- a/lib/core/libimagerror/src/iter.rs +++ b/lib/core/libimagerror/src/iter.rs @@ -118,6 +118,33 @@ impl<I, F, T, E> DoubleEndedIterator for UnwrapWith<I, F> where } } +/// Iterator helper for Unwrap with exiting on error +pub struct UnwrapExit<I, T, E>(I, i32) + where I: Iterator<Item = Result<T, E>>, + E: Error; + +impl<I, T, E> Iterator for UnwrapExit<I, T, E> + where I: Iterator<Item = Result<T, E>>, + E: Error +{ + type Item = T; + + fn next(&mut self) -> Option<Self::Item> { + use trace::MapErrTrace; + self.0.next().map(|e| e.map_err_trace_exit_unwrap(self.1)) + } +} + +impl<I, T, E> DoubleEndedIterator for UnwrapExit<I, T, E> + where I: DoubleEndedIterator<Item = Result<T, E>>, + E: Error +{ + fn next_back(&mut self) -> Option<Self::Item> { + use trace::MapErrTrace; + self.0.next_back().map(|e| e.map_err_trace_exit_unwrap(self.1)) + } +} + /// This trait provides methods that make it easier to work with iterators that yield a `Result`. pub trait TraceIterator<T, E> : Iterator<Item = Result<T, E>> + Sized { /// Creates an iterator that yields the item in each `Ok` item, while filtering out the `Err` @@ -136,6 +163,20 @@ pub trait TraceIterator<T, E> : Iterator<Item = Result<T, E>> + Sized { self.unwrap_with(trace_error) } + /// Creates an iterator that yields the item in each `Ok` item. + /// + /// The first `Err(_)` element is traced using `::trace::trace_error_exit`. + /// + /// As with all iterators, the processing is lazy. If you do not use the result of this method, + /// nothing will be passed to `::trace::trace_error_exit`, no matter how many `Err` items might + /// be present. + #[inline] + fn trace_unwrap_exit(self, exitcode: i32) -> UnwrapExit<Self, T, E> + where E: Error + { + UnwrapExit(self, exitcode) + } + /// Takes a closure and creates an iterator that will call that closure for each `Err` element. /// The resulting iterator will yield the exact same items as the original iterator. A close /// analogue from the standard library would be `Iterator::inspect`. diff --git a/scripts/license-headers-updated b/scripts/license-headers-updated new file mode 100755 index 00000000..cbd8cfe4 --- /dev/null +++ b/scripts/license-headers-updated @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +curr_year=$(date +%Y || exit 1) + +line() { + head -n "$1" | tail -n 1 +} + +check() { + local file="$1" + local line="$2" + local mtch="$3" + local desc="$4" + + cat "$file" | line "$line" | grep "$mtch" 2>/dev/null >/dev/null || { + echo "[LICENSE ERROR]: '$desc' is missing or wrong in '$file'" + return 1 + } +} + +find -name "*.rs" -type f | while read filename; do + check "$filename" 2 \ + "imag - the personal information management suite for the commandline" \ + "Description line" \ + || exit 1 + + check "$filename" 3 \ + "Copyright (C) 2015-${curr_year}" \ + "Copyright name" \ + || exit 1 + + check "$filename" 5 \ + "This library is free software" \ + "License" \ + || exit 1 + + echo "[LICENSE OK]: $filename" +done + |