From 6e80f603d64681254412e14c3b8ebbf8b504531e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 19 Apr 2018 21:36:22 +0200 Subject: [PATCH] Add functionality to list diaries --- bin/domain/imag-diary/Cargo.toml | 1 + bin/domain/imag-diary/src/main.rs | 24 ++++++++++++++++++++++++ bin/domain/imag-diary/src/ui.rs | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/bin/domain/imag-diary/Cargo.toml b/bin/domain/imag-diary/Cargo.toml index 03a2ca3e..91ae9608 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 85da8835..6fa7fb62 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 ac6f130a..a5e54bc0 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")