summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-20 09:24:07 +0200
committerGitHub <noreply@github.com>2018-04-20 09:24:07 +0200
commite0decb72943e28109c228290414822cc7dd53620 (patch)
treeb9558ab1fb6a3009db0dc9706dd89f70463cd2f1
parent705c6a33f198a6d3cecceb902913b77898393745 (diff)
parent6e80f603d64681254412e14c3b8ebbf8b504531e (diff)
downloadimag-e0decb72943e28109c228290414822cc7dd53620.zip
imag-e0decb72943e28109c228290414822cc7dd53620.tar.gz
Merge pull request #1419 from matthiasbeyer/imag-diary/list-diaries
Add functionality to list diaries
-rw-r--r--bin/domain/imag-diary/Cargo.toml1
-rw-r--r--bin/domain/imag-diary/src/main.rs24
-rw-r--r--bin/domain/imag-diary/src/ui.rs4
3 files changed, 29 insertions, 0 deletions
diff --git a/bin/domain/imag-diary/Cargo.toml b/bin/domain/imag-diary/Cargo.toml
index 03a2ca3..91ae960 100644
--- a/bin/domain/imag-diary/Cargo.toml
+++ b/bin/domain/imag-diary/Cargo.toml
@@ -26,6 +26,7 @@ chrono = "0.4"
log = "0.4.0"
toml = "0.4"
toml-query = "0.6"
+itertools = "0.7"
libimagerror = { version = "0.8.0", path = "../../../lib/core/libimagerror" }
libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore" }
diff --git a/bin/domain/imag-diary/src/main.rs b/bin/domain/imag-diary/src/main.rs
index 85da883..6fa7fb6 100644
--- a/bin/domain/imag-diary/src/main.rs
+++ b/bin/domain/imag-diary/src/main.rs
@@ -37,6 +37,7 @@ extern crate clap;
extern crate chrono;
extern crate toml;
extern crate toml_query;
+extern crate itertools;
extern crate libimagdiary;
extern crate libimagentryedit;
@@ -47,9 +48,14 @@ extern crate libimagstore;
extern crate libimagtimeui;
extern crate libimagutil;
+use std::io::Write;
+
use libimagrt::setup::generate_runtime_setup;
+use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
+use itertools::Itertools;
+
mod create;
mod delete;
mod edit;
@@ -76,6 +82,7 @@ fn main() {
.map(|name| {
debug!("Call {}", name);
match name {
+ "diaries" => diaries(&rt),
"create" => create(&rt),
"delete" => delete(&rt),
"edit" => edit(&rt),
@@ -92,3 +99,20 @@ fn main() {
});
}
+fn diaries(rt: &Runtime) {
+ use libimagdiary::diary::Diary;
+ use libimagerror::io::ToExitCode;
+ use libimagerror::exit::ExitUnwrap;
+ use libimagerror::iter::TraceIterator;
+
+ let out = rt.stdout();
+ let mut outlock = out.lock();
+
+ rt.store()
+ .diary_names()
+ .map_err_trace_exit_unwrap(1)
+ .trace_unwrap_exit(1)
+ .unique()
+ .for_each(|n| writeln!(outlock, "{}", n).to_exit_code().unwrap_or_exit())
+}
+
diff --git a/bin/domain/imag-diary/src/ui.rs b/bin/domain/imag-diary/src/ui.rs
index ac6f130..a5e54bc 100644
--- a/bin/domain/imag-diary/src/ui.rs
+++ b/bin/domain/imag-diary/src/ui.rs
@@ -28,6 +28,10 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.required(false)
.help("Use other than default diary"))
+ .subcommand(SubCommand::with_name("diaries")
+ .about("List all available diaries")
+ .version("0.1"))
+
.subcommand(SubCommand::with_name("create")
.about("Create a diary entry")
.version("0.1")