Merge pull request #1292 from matthiasbeyer/fix-broken-pipes
Fix broken pipes
This commit is contained in:
commit
97e863f8fb
26 changed files with 507 additions and 181 deletions
|
@ -43,6 +43,7 @@ extern crate libimagerror;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagentryannotation::annotateable::*;
|
use libimagentryannotation::annotateable::*;
|
||||||
|
@ -50,6 +51,8 @@ use libimagentryannotation::annotation_fetcher::*;
|
||||||
use libimagentryannotation::error::AnnotationError as AE;
|
use libimagentryannotation::error::AnnotationError as AE;
|
||||||
use libimagentryedit::edit::*;
|
use libimagentryedit::edit::*;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
@ -132,6 +135,7 @@ fn remove(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
let scmd = rt.cli().subcommand_matches("list").unwrap(); // safed by clap
|
let scmd = rt.cli().subcommand_matches("list").unwrap(); // safed by clap
|
||||||
let with_text = scmd.is_present("list-with-text");
|
let with_text = scmd.is_present("list-with-text");
|
||||||
match scmd.value_of("entry").map(PathBuf::from) {
|
match scmd.value_of("entry").map(PathBuf::from) {
|
||||||
|
@ -145,7 +149,9 @@ fn list(rt: &Runtime) {
|
||||||
.annotations(rt.store())
|
.annotations(rt.store())
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit_unwrap(1), with_text))
|
.map(|(i, a)| {
|
||||||
|
list_annotation(&mut out, i, a.map_err_trace_exit_unwrap(1), with_text)
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,20 +162,25 @@ fn list(rt: &Runtime) {
|
||||||
.all_annotations()
|
.all_annotations()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, a)| list_annotation(i, a.map_err_trace_exit_unwrap(1), with_text))
|
.map(|(i, a)| {
|
||||||
|
list_annotation(&mut out, i, a.map_err_trace_exit_unwrap(1), with_text)
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_annotation<'a>(i: usize, a: FileLockEntry<'a>, with_text: bool) {
|
fn list_annotation<'a>(out: &mut Write, i: usize, a: FileLockEntry<'a>, with_text: bool) {
|
||||||
if with_text {
|
let _ = if with_text {
|
||||||
println!("--- {i: >5} | {id}\n{text}\n\n",
|
writeln!(out,
|
||||||
|
"--- {i: >5} | {id}\n{text}\n\n",
|
||||||
i = i,
|
i = i,
|
||||||
id = a.get_location(),
|
id = a.get_location(),
|
||||||
text = a.get_content());
|
text = a.get_content())
|
||||||
} else {
|
} else {
|
||||||
println!("{: >5} | {}", i, a.get_location());
|
writeln!(out, "{: >5} | {}", i, a.get_location())
|
||||||
}
|
}
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,12 @@ extern crate libimagerror;
|
||||||
extern crate libimagentrylink;
|
extern crate libimagentrylink;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagstore::error::StoreError as Error;
|
use libimagstore::error::StoreError as Error;
|
||||||
|
@ -151,39 +155,66 @@ fn main() {
|
||||||
|
|
||||||
let n = diags.len();
|
let n = diags.len();
|
||||||
|
|
||||||
println!("imag version {}", env!("CARGO_PKG_VERSION"));
|
let mut out = ::std::io::stdout();
|
||||||
println!("");
|
|
||||||
println!("{} entries", n);
|
let _ = writeln!(out, "imag version {}", env!("CARGO_PKG_VERSION"))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "{} entries", n)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
for (k, v) in version_counts {
|
for (k, v) in version_counts {
|
||||||
println!("{} entries with store version '{}'", v, k);
|
let _ = writeln!(out, "{} entries with store version '{}'", v, k)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
println!("{} header sections in the average entry", sum_header_sections / n);
|
let _ = writeln!(out, "{} header sections in the average entry", sum_header_sections / n)
|
||||||
println!("{} average content bytecount", sum_bytecount_content / n);
|
.to_exit_code()
|
||||||
println!("{} average overall bytecount", sum_overall_byte_size / n);
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "{} average content bytecount", sum_bytecount_content / n)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "{} average overall bytecount", sum_overall_byte_size / n)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
if let Some((num, path)) = max_overall_byte_size {
|
if let Some((num, path)) = max_overall_byte_size {
|
||||||
println!("Largest Entry ({bytes} bytes): {path}",
|
let _ = writeln!(out,
|
||||||
|
"Largest Entry ({bytes} bytes): {path}",
|
||||||
bytes = num,
|
bytes = num,
|
||||||
path = path
|
path = path
|
||||||
.into_pathbuf()
|
.into_pathbuf()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or("Failed converting path to string")
|
.unwrap_or("Failed converting path to string")
|
||||||
);
|
)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
println!("{} average internal link count per entry", num_internal_links / n);
|
let _ = writeln!(out, "{} average internal link count per entry", num_internal_links / n)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
if let Some((num, path)) = max_internal_links {
|
if let Some((num, path)) = max_internal_links {
|
||||||
println!("Entry with most internal links ({count}): {path}",
|
let _ = writeln!(out, "Entry with most internal links ({count}): {path}",
|
||||||
count = num,
|
count = num,
|
||||||
path = path
|
path = path
|
||||||
.into_pathbuf()
|
.into_pathbuf()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or("Failed converting path to string")
|
.unwrap_or("Failed converting path to string")
|
||||||
);
|
)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
println!("{} verified entries", verified_count);
|
let _ = writeln!(out, "{} verified entries", verified_count)
|
||||||
println!("{} unverified entries", unverified_count);
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "{} unverified entries", unverified_count)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ extern crate libimagutil;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
@ -54,6 +55,8 @@ use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
@ -141,8 +144,10 @@ fn remove(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
.map_err_trace_exit_unwrap(1); // The parsing of the deleted values failed
|
.map_err_trace_exit_unwrap(1); // The parsing of the deleted values failed
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
if scmd.is_present("print-removed") {
|
if scmd.is_present("print-removed") {
|
||||||
println!("{}", removed_value);
|
let _ = writeln!(out, "{}", removed_value).to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +174,7 @@ fn get(rt: &Runtime) {
|
||||||
exit(1)
|
exit(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("{}", value);
|
let mut out = ::std::io::stdout();
|
||||||
|
let _ = writeln!(out, "{}", value).to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,15 @@ extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
@ -87,32 +91,38 @@ fn main() {
|
||||||
.map(|entry| show(&entry, &pattern, &opts, &mut count))
|
.map(|entry| show(&entry, &pattern, &opts, &mut count))
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
if opts.count {
|
if opts.count {
|
||||||
println!("{}", count);
|
let _ = writeln!(out, "{}", count).to_exit_code().unwrap_or_exit();
|
||||||
} else if !opts.files_with_matches {
|
} else if !opts.files_with_matches {
|
||||||
println!("Processed {} files, {} matches, {} nonmatches",
|
let _ = writeln!(out, "Processed {} files, {} matches, {} nonmatches",
|
||||||
overall_count,
|
overall_count,
|
||||||
count,
|
count,
|
||||||
overall_count - count);
|
overall_count - count)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(e: &Entry, re: &Regex, opts: &Options, count: &mut usize) {
|
fn show(e: &Entry, re: &Regex, opts: &Options, count: &mut usize) {
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
if opts.files_with_matches {
|
if opts.files_with_matches {
|
||||||
println!("{}", e.get_location());
|
let _ = writeln!(out, "{}", e.get_location()).to_exit_code().unwrap_or_exit();
|
||||||
} else if opts.count {
|
} else if opts.count {
|
||||||
*count += 1;
|
*count += 1;
|
||||||
} else {
|
} else {
|
||||||
println!("{}:", e.get_location());
|
let _ = writeln!(out, "{}:", e.get_location()).to_exit_code().unwrap_or_exit();
|
||||||
for capture in re.captures_iter(e.get_content()) {
|
for capture in re.captures_iter(e.get_content()) {
|
||||||
for mtch in capture.iter() {
|
for mtch in capture.iter() {
|
||||||
if let Some(m) = mtch {
|
if let Some(m) = mtch {
|
||||||
println!(" '{}'", m.as_str());
|
let _ = writeln!(out, " '{}'", m.as_str()).to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("");
|
let _ = writeln!(out, "").to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = ">=2.29"
|
version = ">=2.29"
|
||||||
|
|
|
@ -37,6 +37,8 @@ extern crate clap;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
|
||||||
|
extern crate libimagerror;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
|
@ -45,6 +47,9 @@ use std::path::PathBuf;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
|
||||||
const CONFIGURATION_STR : &'static str = include_str!("../imagrc.toml");
|
const CONFIGURATION_STR : &'static str = include_str!("../imagrc.toml");
|
||||||
|
|
||||||
const GITIGNORE_STR : &'static str = r#"
|
const GITIGNORE_STR : &'static str = r#"
|
||||||
|
@ -63,6 +68,7 @@ imagrc.toml
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = ui::build_ui();
|
let app = ui::build_ui();
|
||||||
let matches = app.get_matches();
|
let matches = app.get_matches();
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
let path = matches
|
let path = matches
|
||||||
.value_of("path")
|
.value_of("path")
|
||||||
|
@ -73,8 +79,12 @@ fn main() {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(|mut p| { p.push(".imag"); p })
|
.map(|mut p| { p.push(".imag"); p })
|
||||||
.map(|path| if path.exists() {
|
.map(|path| if path.exists() {
|
||||||
println!("Path '{:?}' already exists!", path);
|
let _ = writeln!(out, "Path '{:?}' already exists!", path)
|
||||||
println!("Cannot continue.");
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "Cannot continue.")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
::std::process::exit(1)
|
::std::process::exit(1)
|
||||||
} else {
|
} else {
|
||||||
path
|
path
|
||||||
|
@ -109,7 +119,9 @@ fn main() {
|
||||||
|
|
||||||
if find_command("git").is_some() && !matches.is_present("nogit") {
|
if find_command("git").is_some() && !matches.is_present("nogit") {
|
||||||
// we initialize a git repository
|
// we initialize a git repository
|
||||||
println!("Going to initialize a git repository in the imag directory...");
|
let _ = writeln!(out, "Going to initialize a git repository in the imag directory...")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
|
||||||
let gitignore_path = {
|
let gitignore_path = {
|
||||||
let mut gitignore_path = path.clone();
|
let mut gitignore_path = path.clone();
|
||||||
|
@ -138,10 +150,16 @@ fn main() {
|
||||||
.expect("Calling 'git init' failed");
|
.expect("Calling 'git init' failed");
|
||||||
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
println!("{}", String::from_utf8(output.stdout).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stdout).expect("No UTF-8 output"))
|
||||||
println!("'git {} {} --no-pager init' succeeded", worktree, gitdir);
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "'git {} {} --no-pager init' succeeded", worktree, gitdir)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
println!("{}", String::from_utf8(output.stderr).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
::std::process::exit(output.status.code().unwrap_or(1));
|
::std::process::exit(output.status.code().unwrap_or(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,10 +170,16 @@ fn main() {
|
||||||
.output()
|
.output()
|
||||||
.expect("Calling 'git add' failed");
|
.expect("Calling 'git add' failed");
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
println!("{}", String::from_utf8(output.stdout).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stdout).expect("No UTF-8 output"))
|
||||||
println!("'git {} {} --no-pager add {}' succeeded", worktree, gitdir, gitignore_path);
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "'git {} {} --no-pager add {}' succeeded", worktree, gitdir, gitignore_path)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
println!("{}", String::from_utf8(output.stderr).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
::std::process::exit(output.status.code().unwrap_or(1));
|
::std::process::exit(output.status.code().unwrap_or(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,20 +190,32 @@ fn main() {
|
||||||
.output()
|
.output()
|
||||||
.expect("Calling 'git commit' failed");
|
.expect("Calling 'git commit' failed");
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
println!("{}", String::from_utf8(output.stdout).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stdout).expect("No UTF-8 output"))
|
||||||
println!("'git {} {} --no-pager commit {} -m 'Initial import'' succeeded", worktree, gitdir, gitignore_path);
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "'git {} {} --no-pager commit {} -m 'Initial import'' succeeded", worktree, gitdir, gitignore_path)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
println!("{}", String::from_utf8(output.stderr).expect("No UTF-8 output"));
|
let _ = writeln!(out, "{}", String::from_utf8(output.stderr).expect("No UTF-8 output"))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
::std::process::exit(output.status.code().unwrap_or(1));
|
::std::process::exit(output.status.code().unwrap_or(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("git stuff finished!");
|
let _ = writeln!(out, "git stuff finished!")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
} else {
|
} else {
|
||||||
println!("No git repository will be initialized");
|
let _ = writeln!(out, "No git repository will be initialized")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Ready. Have fun with imag!");
|
let _ = writeln!(out, "Ready. Have fun with imag!")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config() -> String {
|
fn get_config() -> String {
|
||||||
|
|
|
@ -50,6 +50,7 @@ extern crate libimagutil;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagentrylink::external::ExternalLinker;
|
use libimagentrylink::external::ExternalLinker;
|
||||||
|
@ -57,6 +58,8 @@ use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagentrylink::internal::store_check::StoreLinkConsistentExt;
|
use libimagentrylink::internal::store_check::StoreLinkConsistentExt;
|
||||||
use libimagentrylink::error::LinkError as LE;
|
use libimagentrylink::error::LinkError as LE;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagstore::error::StoreError;
|
use libimagstore::error::StoreError;
|
||||||
|
@ -227,6 +230,7 @@ fn list_linkings(rt: &Runtime) {
|
||||||
.unwrap(); // safed by clap
|
.unwrap(); // safed by clap
|
||||||
|
|
||||||
let list_externals = cmd.is_present("list-externals-too");
|
let list_externals = cmd.is_present("list-externals-too");
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
for entry in cmd.values_of("entries").unwrap() { // safed by clap
|
for entry in cmd.values_of("entries").unwrap() { // safed by clap
|
||||||
match rt.store().get(PathBuf::from(entry)) {
|
match rt.store().get(PathBuf::from(entry)) {
|
||||||
|
@ -240,20 +244,27 @@ fn list_linkings(rt: &Runtime) {
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if let Some(link) = link {
|
if let Some(link) = link {
|
||||||
println!("{: <3}: {}", i, link);
|
let _ = writeln!(out, "{: <3}: {}", i, link)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if list_externals {
|
if list_externals {
|
||||||
for link in entry.get_external_links(rt.store()).map_err_trace_exit_unwrap(1) {
|
entry.get_external_links(rt.store())
|
||||||
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
.enumerate()
|
||||||
|
.for_each(|(i, link)| {
|
||||||
let link = link
|
let link = link
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.into_string();
|
.into_string();
|
||||||
|
|
||||||
println!("{: <3}: {}", i, link);
|
let _ = writeln!(out, "{: <3}: {}", i, link)
|
||||||
i += 1;
|
.to_exit_code()
|
||||||
}
|
.unwrap_or_exit();
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(None) => warn!("Not found: {}", entry),
|
Ok(None) => warn!("Not found: {}", entry),
|
||||||
|
|
|
@ -17,14 +17,18 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::*;
|
use libimagerror::trace::*;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
|
||||||
pub fn ids(rt: &Runtime) {
|
pub fn ids(rt: &Runtime) {
|
||||||
let full = rt.cli().subcommand_matches("ids").unwrap() //secured by main
|
let full = rt.cli().subcommand_matches("ids").unwrap() //secured by main
|
||||||
.is_present("full");
|
.is_present("full");
|
||||||
let base = rt.store().path();
|
let base = rt.store().path();
|
||||||
let _ :Vec<_> = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -35,7 +39,9 @@ pub fn ids(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
.map(|i| i.to_str())
|
.map(|i| i.to_str())
|
||||||
.map(|elem| elem.map_err_trace_exit_unwrap(1))
|
.map(|elem| elem.map_err_trace_exit_unwrap(1))
|
||||||
.map(|i| println!("{}", i))
|
.map(|i| writeln!(::std::io::stdout(), "{}", i))
|
||||||
.collect();
|
.collect::<Result<Vec<()>, ::std::io::Error>>()
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
pub fn retrieve(rt: &Runtime) {
|
pub fn retrieve(rt: &Runtime) {
|
||||||
|
@ -48,9 +51,13 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
if do_print_raw(scmd) {
|
if do_print_raw(scmd) {
|
||||||
debug!("Printing raw content...");
|
debug!("Printing raw content...");
|
||||||
println!("{}", e.to_str());
|
let _ = writeln!(out, "{}", e.to_str())
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
} else if do_filter(scmd) {
|
} else if do_filter(scmd) {
|
||||||
debug!("Filtering...");
|
debug!("Filtering...");
|
||||||
warn!("Filtering via header specs is currently now supported.");
|
warn!("Filtering via header specs is currently now supported.");
|
||||||
|
@ -67,13 +74,17 @@ pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
} else {
|
} else {
|
||||||
debug!("Printing header as TOML...");
|
debug!("Printing header as TOML...");
|
||||||
println!("{}", e.get_header())
|
let _ = writeln!(out, "{}", e.get_header())
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if do_print_content(scmd) {
|
if do_print_content(scmd) {
|
||||||
debug!("Printing content...");
|
debug!("Printing content...");
|
||||||
println!("{}", e.get_content());
|
let _ = writeln!(out, "{}", e.get_content())
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ extern crate toml_query;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
|
@ -48,6 +49,8 @@ use libimagentrytag::tagable::Tagable;
|
||||||
use libimagentrytag::tag::Tag;
|
use libimagentrytag::tag::Tag;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
|
|
||||||
|
@ -161,19 +164,27 @@ fn list(id: PathBuf, rt: &Runtime) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
if line_out {
|
if line_out {
|
||||||
for tag in &tags {
|
for tag in &tags {
|
||||||
println!("{}", tag);
|
let _ = writeln!(out, "{}", tag)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sepp_out {
|
if sepp_out {
|
||||||
let sepp = scmd.value_of("sep").unwrap(); // we checked before
|
let sepp = scmd.value_of("sep").unwrap(); // we checked before
|
||||||
println!("{}", tags.join(sepp));
|
let _ = writeln!(out, "{}", tags.join(sepp))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if comm_out {
|
if comm_out {
|
||||||
println!("{}", tags.join(", "));
|
let _ = writeln!(out, "{}", tags.join(", "))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ use std::process::exit;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
use std::io::{stdout, Stdout, Write};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
@ -40,6 +41,8 @@ use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
|
||||||
/// Returns the helptext, putting the Strings in cmds as possible
|
/// Returns the helptext, putting the Strings in cmds as possible
|
||||||
/// subcommands into it
|
/// subcommands into it
|
||||||
|
@ -85,10 +88,12 @@ fn help_text(cmds: Vec<String>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of imag-* executables found in $PATH
|
/// Returns the list of imag-* executables found in $PATH
|
||||||
fn get_commands() -> Vec<String> {
|
fn get_commands(out: &mut Stdout) -> Vec<String> {
|
||||||
let mut v = match env::var("PATH") {
|
let mut v = match env::var("PATH") {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("PATH error: {:?}", e);
|
let _ = writeln!(out, "PATH error: {:?}", e)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(1)
|
exit(1)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -122,7 +127,8 @@ fn main() {
|
||||||
let appname = "imag";
|
let appname = "imag";
|
||||||
let version = make_imag_version!();
|
let version = make_imag_version!();
|
||||||
let about = "imag - the PIM suite for the commandline";
|
let about = "imag - the PIM suite for the commandline";
|
||||||
let commands = get_commands();
|
let mut out = stdout();
|
||||||
|
let commands = get_commands(&mut out);
|
||||||
let helptext = help_text(commands.clone());
|
let helptext = help_text(commands.clone());
|
||||||
let mut 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])
|
.settings(&[AppSettings::AllowExternalSubcommands, AppSettings::ArgRequiredElseHelp])
|
||||||
|
@ -152,14 +158,18 @@ fn main() {
|
||||||
{
|
{
|
||||||
let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false);
|
let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false);
|
||||||
if print_help {
|
if print_help {
|
||||||
println!("{}", long_help);
|
let _ = writeln!(out, "{}", long_help)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(0)
|
exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rt = Runtime::new(app)
|
let rt = Runtime::new(app)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
println!("Runtime couldn't be setup. Exiting");
|
let _ = writeln!(out, "Runtime couldn't be setup. Exiting")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
@ -171,7 +181,9 @@ fn main() {
|
||||||
|
|
||||||
if matches.is_present("version") {
|
if matches.is_present("version") {
|
||||||
debug!("Showing version");
|
debug!("Showing version");
|
||||||
println!("imag {}", env!("CARGO_PKG_VERSION"));
|
let _ = writeln!(out, "imag {}", env!("CARGO_PKG_VERSION"))
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +206,9 @@ fn main() {
|
||||||
})
|
})
|
||||||
.fold((), |_, line| {
|
.fold((), |_, line| {
|
||||||
// The amount of newlines may differ depending on the subprocess
|
// The amount of newlines may differ depending on the subprocess
|
||||||
println!("{}", line.trim());
|
let _ = writeln!(out, "{}", line.trim())
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -203,9 +217,13 @@ fn main() {
|
||||||
let aliases = match fetch_aliases(&rt) {
|
let aliases = match fetch_aliases(&rt) {
|
||||||
Ok(aliases) => aliases,
|
Ok(aliases) => aliases,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error while fetching aliases from configuration file");
|
let _ = writeln!(out, "Error while fetching aliases from configuration file")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
debug!("Error = {:?}", e);
|
debug!("Error = {:?}", e);
|
||||||
println!("Aborting");
|
let _ = writeln!(out, "Aborting")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -250,16 +268,24 @@ fn main() {
|
||||||
debug!("Error calling the subcommand");
|
debug!("Error calling the subcommand");
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
ErrorKind::NotFound => {
|
ErrorKind::NotFound => {
|
||||||
println!("No such command: 'imag-{}'", subcommand);
|
let _ = writeln!(out, "No such command: 'imag-{}'", subcommand)
|
||||||
println!("See 'imag --help' for available subcommands");
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "See 'imag --help' for available subcommands")
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(1);
|
exit(1);
|
||||||
},
|
},
|
||||||
ErrorKind::PermissionDenied => {
|
ErrorKind::PermissionDenied => {
|
||||||
println!("No permission to execute: 'imag-{}'", subcommand);
|
let _ = writeln!(out, "No permission to execute: 'imag-{}'", subcommand)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(1);
|
exit(1);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
println!("Error spawning: {:?}", e);
|
let _ = writeln!(out, "Error spawning: {:?}", e)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ extern crate libimagbookmark;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadTypeExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
@ -53,6 +54,8 @@ use libimagbookmark::collection::BookmarkCollectionStore;
|
||||||
use libimagbookmark::error::BookmarkError as BE;
|
use libimagbookmark::error::BookmarkError as BE;
|
||||||
use libimagbookmark::link::Link as BookmarkLink;
|
use libimagbookmark::link::Link as BookmarkLink;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
@ -132,10 +135,11 @@ fn list(rt: &Runtime) {
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let links = collection.links(rt.store()).map_err_trace_exit_unwrap(1);
|
let links = collection.links(rt.store()).map_err_trace_exit_unwrap(1);
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
debug!("Listing...");
|
debug!("Listing...");
|
||||||
for (i, link) in links.enumerate() {
|
for (i, link) in links.enumerate() {
|
||||||
match link {
|
match link {
|
||||||
Ok(link) => println!("{: >3}: {}", i, link),
|
Ok(link) => writeln!(out, "{: >3}: {}", i, link).to_exit_code().unwrap_or_exit(),
|
||||||
Err(e) => trace_error(&e)
|
Err(e) => trace_error(&e)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,6 +52,7 @@ extern crate libimagentryedit;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
@ -63,6 +64,8 @@ use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::str::ErrFromStr;
|
use libimagerror::str::ErrFromStr;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagcontact::store::ContactStore;
|
use libimagcontact::store::ContactStore;
|
||||||
use libimagcontact::error::ContactError as CE;
|
use libimagcontact::error::ContactError as CE;
|
||||||
use libimagcontact::contact::Contact;
|
use libimagcontact::contact::Contact;
|
||||||
|
@ -105,6 +108,7 @@ fn main() {
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
let scmd = rt.cli().subcommand_matches("list").unwrap();
|
let scmd = rt.cli().subcommand_matches("list").unwrap();
|
||||||
let list_format = get_contact_print_format("contact.list_format", rt, &scmd);
|
let list_format = get_contact_print_format("contact.list_format", rt, &scmd);
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
|
@ -138,7 +142,8 @@ fn list(rt: &Runtime) {
|
||||||
.err_from_str()
|
.err_from_str()
|
||||||
.map_err(CE::from)
|
.map_err(CE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
println!("{}", s);
|
|
||||||
|
writeln!(out, "{}", s).to_exit_code().unwrap_or_exit()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
}
|
}
|
||||||
|
@ -206,7 +211,7 @@ fn show(rt: &Runtime) {
|
||||||
.err_from_str()
|
.err_from_str()
|
||||||
.map_err(CE::from)
|
.map_err(CE::from)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
println!("{}", s);
|
let _ = writeln!(::std::io::stdout(), "{}", s).to_exit_code().unwrap_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: &ArgMatches) -> Handlebars {
|
fn get_contact_print_format(config_value_path: &'static str, rt: &Runtime, scmd: &ArgMatches) -> Handlebars {
|
||||||
|
|
|
@ -48,8 +48,11 @@ extern crate libimagstore;
|
||||||
extern crate libimagtimeui;
|
extern crate libimagtimeui;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
|
|
||||||
mod create;
|
mod create;
|
||||||
|
@ -77,8 +80,9 @@ fn main() {
|
||||||
if rt.is_ok() {
|
if rt.is_ok() {
|
||||||
rt.unwrap()
|
rt.unwrap()
|
||||||
} else {
|
} else {
|
||||||
println!("Could not set up Runtime");
|
let mut out = ::std::io::stdout();
|
||||||
println!("{:?}", rt.err().unwrap());
|
let _ = writeln!(out, "Could not set up Runtime").to_exit_code().unwrap_or_exit();
|
||||||
|
let _ = writeln!(out, "{:?}", rt.err().unwrap()).to_exit_code().unwrap_or_exit();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,11 +47,14 @@ extern crate libimagutil;
|
||||||
extern crate libimagentrylist;
|
extern crate libimagentrylist;
|
||||||
extern crate libimaginteraction;
|
extern crate libimaginteraction;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimaghabit::store::HabitStore;
|
use libimaghabit::store::HabitStore;
|
||||||
use libimaghabit::habit::builder::HabitBuilder;
|
use libimaghabit::habit::builder::HabitBuilder;
|
||||||
use libimaghabit::habit::HabitTemplate;
|
use libimaghabit::habit::HabitTemplate;
|
||||||
|
@ -389,6 +392,7 @@ fn show(rt: &Runtime) {
|
||||||
vec![date, comm]
|
vec![date, comm]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
|
@ -403,12 +407,15 @@ fn show(rt: &Runtime) {
|
||||||
let recur = habit.habit_recur_spec().map_err_trace_exit_unwrap(1);
|
let recur = habit.habit_recur_spec().map_err_trace_exit_unwrap(1);
|
||||||
let comm = habit.habit_comment().map_err_trace_exit_unwrap(1);
|
let comm = habit.habit_comment().map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
println!("{i} - {name}\nBase : {b},\nRecurrence: {r}\nComment : {c}\n",
|
let _ = writeln!(out,
|
||||||
|
"{i} - {name}\nBase : {b},\nRecurrence: {r}\nComment : {c}\n",
|
||||||
i = i,
|
i = i,
|
||||||
name = name,
|
name = name,
|
||||||
b = basedate,
|
b = basedate,
|
||||||
r = recur,
|
r = recur,
|
||||||
c = comm);
|
c = comm)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
|
||||||
let instances_iter = habit
|
let instances_iter = habit
|
||||||
.linked_instances()
|
.linked_instances()
|
||||||
|
|
|
@ -43,9 +43,13 @@ extern crate libimaglog;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagdiary;
|
extern crate libimagdiary;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagdiary::diary::Diary;
|
use libimagdiary::diary::Diary;
|
||||||
use libimaglog::log::Log;
|
use libimaglog::log::Log;
|
||||||
use libimaglog::error::LogError as LE;
|
use libimaglog::error::LogError as LE;
|
||||||
|
@ -117,28 +121,30 @@ fn show(rt: &Runtime) {
|
||||||
};
|
};
|
||||||
|
|
||||||
for iter in iters {
|
for iter in iters {
|
||||||
for element in iter {
|
let _ = iter.map(|element| {
|
||||||
let e = element.map_err_trace_exit_unwrap(1);
|
let e = element.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
if !e.is_log().map_err_trace_exit_unwrap(1) {
|
if !e.is_log().map_err_trace_exit_unwrap(1) {
|
||||||
continue;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = e.diary_id().map_err_trace_exit_unwrap(1);
|
let id = e.diary_id().map_err_trace_exit_unwrap(1);
|
||||||
println!("{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
|
writeln!(::std::io::stdout(),
|
||||||
|
"{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
|
||||||
dname = id.diary_name(),
|
dname = id.diary_name(),
|
||||||
y = id.year(),
|
y = id.year(),
|
||||||
m = id.month(),
|
m = id.month(),
|
||||||
d = id.day(),
|
d = id.day(),
|
||||||
H = id.hour(),
|
H = id.hour(),
|
||||||
M = id.minute(),
|
M = id.minute(),
|
||||||
text = e.get_content());
|
text = e.get_content())
|
||||||
|
.to_exit_code()
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<()>, _>>()
|
||||||
|
.unwrap_or_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Ready.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_diary_name(rt: &Runtime) -> String {
|
fn get_diary_name(rt: &Runtime) -> String {
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
use toml_query::read::TomlValueReadTypeExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
|
@ -25,7 +25,11 @@ extern crate libimagmail;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagmail::mail::Mail;
|
use libimagmail::mail::Mail;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
|
@ -106,12 +110,13 @@ fn list(rt: &Runtime) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n",
|
writeln!(::std::io::stdout(),
|
||||||
|
"Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n",
|
||||||
from = from,
|
from = from,
|
||||||
id = id,
|
id = id,
|
||||||
subj = subject,
|
subj = subject,
|
||||||
to = to
|
to = to
|
||||||
);
|
).to_exit_code().unwrap_or_exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern crate libimagerror;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -39,6 +40,8 @@ use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
use libimagnotes::note::Note;
|
use libimagnotes::note::Note;
|
||||||
use libimagnotes::notestore::*;
|
use libimagnotes::notestore::*;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagutil::info_result::*;
|
use libimagutil::info_result::*;
|
||||||
use libimagutil::warn_result::WarnResult;
|
use libimagutil::warn_result::WarnResult;
|
||||||
|
@ -116,6 +119,8 @@ fn edit(rt: &Runtime) {
|
||||||
fn list(rt: &Runtime) {
|
fn list(rt: &Runtime) {
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
let _ = rt
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
.all_notes()
|
.all_notes()
|
||||||
|
@ -133,10 +138,10 @@ fn list(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|note| {
|
.for_each(|note| {
|
||||||
note.get_name()
|
let name = note.get_name().map_err_trace_exit_unwrap(1);
|
||||||
.map(|name| println!("{}", name))
|
writeln!(out, "{}", name)
|
||||||
.map_err_trace()
|
.to_exit_code()
|
||||||
.ok();
|
.unwrap_or_exit()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
|
@ -25,6 +26,7 @@ use chrono::NaiveDateTime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
|
@ -84,6 +86,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
tags_filter.and(start_time_filter).and(end_time_filter)
|
tags_filter.and(start_time_filter).and(end_time_filter)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -91,8 +94,7 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
.map(|e| -> Result<_, TTE> {
|
||||||
acc.and_then(|_| {
|
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
let tag = e.get_timetrack_tag()?;
|
let tag = e.get_timetrack_tag()?;
|
||||||
|
@ -104,17 +106,19 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
let end = e.get_end_datetime()?;
|
let end = e.get_end_datetime()?;
|
||||||
debug!(" -> end = {:?}", end);
|
debug!(" -> end = {:?}", end);
|
||||||
|
|
||||||
|
Ok((tag, start, end))
|
||||||
|
})
|
||||||
|
.trace_unwrap_exit(1)
|
||||||
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => println!("{} has no start time.", tag),
|
(None, _) => writeln!(out, "{} has no start time.", tag),
|
||||||
(Some(s), None) => println!("{} | {} - ...", tag, s),
|
(Some(s), None) => writeln!(out, "{} | {} - ...", tag, s),
|
||||||
(Some(s), Some(e)) => println!("{} | {} - {}", tag, s, e),
|
(Some(s), Some(e)) => writeln!(out, "{} | {} - {}", tag, s, e),
|
||||||
}
|
}
|
||||||
|
.to_exit_code()
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
.collect::<Result<Vec<()>, _>>()
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.unwrap_or_else(|e| e.code())
|
||||||
.unwrap_or(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
|
@ -24,6 +25,7 @@ use chrono::NaiveDateTime;
|
||||||
|
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
|
@ -99,6 +101,8 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
tags_filter.and(start_time_filter).and(end_time_filter)
|
tags_filter.and(start_time_filter).and(end_time_filter)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -106,8 +110,7 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
.map(|e| -> Result<_, TTE> {
|
||||||
acc.and_then(|_| {
|
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
let tag = e.get_timetrack_tag()?;
|
let tag = e.get_timetrack_tag()?;
|
||||||
|
@ -119,17 +122,19 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
let end = e.get_end_datetime()?;
|
let end = e.get_end_datetime()?;
|
||||||
debug!(" -> end = {:?}", end);
|
debug!(" -> end = {:?}", end);
|
||||||
|
|
||||||
|
Ok((tag, start, end))
|
||||||
|
})
|
||||||
|
.trace_unwrap_exit(1)
|
||||||
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => println!("{} has no start time.", tag),
|
(None, _) => writeln!(out, "{} has no start time.", tag),
|
||||||
(Some(s), None) => println!("{} | {} - ...", tag, s),
|
(Some(s), None) => writeln!(out, "{} | {} - ...", tag, s),
|
||||||
(Some(s), Some(e)) => println!("{} | {} - {}", tag, s, e),
|
(Some(s), Some(e)) => writeln!(out, "{} | {} - {}", tag, s, e),
|
||||||
}
|
}
|
||||||
|
.to_exit_code()
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
.collect::<Result<Vec<()>, _>>()
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.unwrap_or_else(|e| e.code())
|
||||||
.unwrap_or(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
|
@ -25,6 +26,7 @@ use chrono::NaiveDateTime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
|
@ -97,6 +99,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
tags_filter.and(start_time_filter).and(end_time_filter)
|
tags_filter.and(start_time_filter).and(end_time_filter)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -104,8 +107,7 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
.map(|e| -> Result<_, TTE> {
|
||||||
acc.and_then(|_| {
|
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
let tag = e.get_timetrack_tag()?;
|
let tag = e.get_timetrack_tag()?;
|
||||||
|
@ -117,17 +119,19 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
let end = e.get_end_datetime()?;
|
let end = e.get_end_datetime()?;
|
||||||
debug!(" -> end = {:?}", end);
|
debug!(" -> end = {:?}", end);
|
||||||
|
|
||||||
|
Ok((tag, start, end))
|
||||||
|
})
|
||||||
|
.trace_unwrap_exit(1)
|
||||||
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => println!("{} has no start time.", tag),
|
(None, _) => writeln!(out, "{} has no start time.", tag),
|
||||||
(Some(s), None) => println!("{} | {} - ...", tag, s),
|
(Some(s), None) => writeln!(out, "{} | {} - ...", tag, s),
|
||||||
(Some(s), Some(e)) => println!("{} | {} - {}", tag, s, e),
|
(Some(s), Some(e)) => writeln!(out, "{} | {} - {}", tag, s, e),
|
||||||
}
|
}
|
||||||
|
.to_exit_code()
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
.collect::<Result<Vec<()>, _>>()
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.unwrap_or_else(|e| e.code())
|
||||||
.unwrap_or(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
|
@ -25,6 +26,7 @@ use chrono::NaiveDateTime;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagtimetrack::error::TimeTrackError as TTE;
|
use libimagtimetrack::error::TimeTrackError as TTE;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
|
@ -96,6 +98,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
tags_filter.and(start_time_filter).and(end_time_filter)
|
tags_filter.and(start_time_filter).and(end_time_filter)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut out = ::std::io::stdout();
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -103,8 +106,7 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
.filter(Option::is_some)
|
.filter(Option::is_some)
|
||||||
.map(Option::unwrap)
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
.map(|e| -> Result<_, TTE> {
|
||||||
acc.and_then(|_| {
|
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
let tag = e.get_timetrack_tag()?;
|
let tag = e.get_timetrack_tag()?;
|
||||||
|
@ -116,17 +118,19 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
let end = e.get_end_datetime()?;
|
let end = e.get_end_datetime()?;
|
||||||
debug!(" -> end = {:?}", end);
|
debug!(" -> end = {:?}", end);
|
||||||
|
|
||||||
|
Ok((tag, start, end))
|
||||||
|
})
|
||||||
|
.trace_unwrap_exit(1)
|
||||||
|
.map(|(tag, start, end)| {
|
||||||
match (start, end) {
|
match (start, end) {
|
||||||
(None, _) => println!("{} has no start time.", tag),
|
(None, _) => writeln!(out, "{} has no start time.", tag),
|
||||||
(Some(s), None) => println!("{} | {} - ...", tag, s),
|
(Some(s), None) => writeln!(out, "{} | {} - ...", tag, s),
|
||||||
(Some(s), Some(e)) => println!("{} | {} - {}", tag, s, e),
|
(Some(s), Some(e)) => writeln!(out, "{} | {} - {}", tag, s, e),
|
||||||
}
|
}
|
||||||
|
.to_exit_code()
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
.collect::<Result<Vec<()>, _>>()
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.unwrap_or_else(|e| e.code())
|
||||||
.unwrap_or(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,14 @@ extern crate libimagtodo;
|
||||||
|
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagtodo::taskstore::TaskStore;
|
use libimagtodo::taskstore::TaskStore;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
@ -68,7 +71,10 @@ fn tw_hook(rt: &Runtime) {
|
||||||
.import_task_from_reader(stdin)
|
.import_task_from_reader(stdin)
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
println!("{}\nTask {} stored in imag", line, uuid);
|
let _ = writeln!(::std::io::stdout(), "{}\nTask {} stored in imag", line, uuid)
|
||||||
|
.to_exit_code()
|
||||||
|
.unwrap_or_exit();
|
||||||
|
|
||||||
} else if subcmd.is_present("delete") {
|
} else if subcmd.is_present("delete") {
|
||||||
// The used hook is "on-modify". This hook gives two json-objects
|
// The used hook is "on-modify". This hook gives two json-objects
|
||||||
// per usage und wants one (the second one) back.
|
// per usage und wants one (the second one) back.
|
||||||
|
@ -142,7 +148,7 @@ fn list(rt: &Runtime) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// and then print that
|
// and then print that
|
||||||
println!("{}", outstring);
|
let _ = writeln!(::std::io::stdout(), "{}", outstring).to_exit_code().unwrap_or_exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
res.map_err_trace().ok();
|
res.map_err_trace().ok();
|
||||||
|
|
43
lib/core/libimagerror/src/exit.rs
Normal file
43
lib/core/libimagerror/src/exit.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 the imag contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
pub struct ExitCode(i32);
|
||||||
|
|
||||||
|
impl From<i32> for ExitCode {
|
||||||
|
fn from(i: i32) -> ExitCode {
|
||||||
|
ExitCode(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExitCode {
|
||||||
|
pub fn code(self) -> i32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ExitUnwrap<T> {
|
||||||
|
fn unwrap_or_exit(self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E: Into<ExitCode>> ExitUnwrap<T> for Result<T, E> {
|
||||||
|
fn unwrap_or_exit(self) -> T {
|
||||||
|
self.map_err(Into::into).unwrap_or_else(|e| ::std::process::exit(e.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
62
lib/core/libimagerror/src/io.rs
Normal file
62
lib/core/libimagerror/src/io.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 the imag contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use std::io::ErrorKind;
|
||||||
|
|
||||||
|
use exit::ExitCode;
|
||||||
|
|
||||||
|
pub enum Settings {
|
||||||
|
Ignore(ErrorKind),
|
||||||
|
IgnoreAny(Vec<ErrorKind>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToExitCode<T> {
|
||||||
|
fn to_exit_code(self) -> Result<T, ExitCode>;
|
||||||
|
fn to_exit_code_with(self, Settings) -> Result<T, ExitCode>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> ToExitCode<T> for Result<T, ::std::io::Error> {
|
||||||
|
|
||||||
|
/// Returns an exit code of 0 if the error was a broken pipe, else 1
|
||||||
|
fn to_exit_code(self) -> Result<T, ExitCode> {
|
||||||
|
self.to_exit_code_with(Settings::Ignore(ErrorKind::BrokenPipe))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns an exit code depending on the settings
|
||||||
|
///
|
||||||
|
/// Via the settings, errors can be ignores (translates to exit code zero). All other errors
|
||||||
|
/// are translated into exit code 1
|
||||||
|
///
|
||||||
|
fn to_exit_code_with(self, settings: Settings) -> Result<T, ExitCode> {
|
||||||
|
self.map_err(move |e| match settings {
|
||||||
|
Settings::Ignore(kind) => if e.kind() == kind {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
},
|
||||||
|
Settings::IgnoreAny(v) => if v.iter().any(|el| e.kind() == *el) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.map_err(ExitCode::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,6 +37,8 @@
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|
||||||
|
pub mod io;
|
||||||
|
pub mod exit;
|
||||||
pub mod trace;
|
pub mod trace;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod str;
|
pub mod str;
|
||||||
|
|
Loading…
Reference in a new issue