libimagdiaryfrontend/
lib.rs1#![forbid(unsafe_code)]
21
22#![deny(
23 non_camel_case_types,
24 non_snake_case,
25 path_statements,
26 trivial_numeric_casts,
27 unstable_features,
28 unused_allocation,
29 unused_import_braces,
30 unused_imports,
31 unused_must_use,
32 unused_mut,
33 unused_qualifications,
34 while_true,
35)]
36
37#[macro_use] extern crate log;
38#[macro_use] extern crate failure;
39extern crate resiter;
40extern crate clap;
41extern crate chrono;
42extern crate toml;
43extern crate toml_query;
44extern crate itertools;
45extern crate option_inspect;
46
47extern crate libimagdiary;
48extern crate libimagentryedit;
49extern crate libimagentryview;
50extern crate libimagerror;
51extern crate libimaginteraction;
52extern crate libimagrt;
53extern crate libimagstore;
54extern crate libimagtimeui;
55extern crate libimagutil;
56
57use std::io::Write;
58
59use libimagrt::runtime::Runtime;
60use libimagrt::application::ImagApplication;
61
62use itertools::Itertools;
63use clap::App;
64use failure::Fallible as Result;
65use failure::err_msg;
66use failure::Error;
67
68mod create;
69mod delete;
70mod list;
71mod ui;
72mod util;
73mod view;
74
75use crate::create::create;
76use crate::delete::delete;
77use crate::list::list;
78use crate::view::view;
79
80pub enum ImagDiary {}
85impl ImagApplication for ImagDiary {
86 fn run(rt: Runtime) -> Result<()> {
87 match rt.cli().subcommand_name().ok_or_else(|| err_msg("No subcommand called"))? {
88 "diaries" => diaries(&rt),
89 "create" => create(&rt),
90 "delete" => delete(&rt),
91 "list" => list(&rt),
92 "view" => view(&rt),
93 other => {
94 debug!("Unknown command");
95 if rt.handle_unknown_subcommand("imag-diary", other, rt.cli())?.success() {
96 Ok(())
97 } else {
98 Err(err_msg("Failed to handle unknown subcommand"))
99 }
100 },
101 }
102 }
103
104 fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
105 ui::build_ui(app)
106 }
107
108 fn name() -> &'static str {
109 env!("CARGO_PKG_NAME")
110 }
111
112 fn description() -> &'static str {
113 "Personal Diary/Diaries"
114 }
115
116 fn version() -> &'static str {
117 env!("CARGO_PKG_VERSION")
118 }
119}
120
121fn diaries(rt: &Runtime) -> Result<()> {
122 use libimagdiary::diary::Diary;
123
124 let out = rt.stdout();
125 let mut outlock = out.lock();
126
127 rt.store()
128 .diary_names()?
129 .collect::<Result<Vec<String>>>()?
130 .into_iter()
131 .unique()
132 .map(|n| writeln!(outlock, "{}", n).map_err(Error::from))
133 .collect()
134}
135