From d1fc8c3995cb5464742d3c138078ec65db4cd7bc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 4 Feb 2018 19:50:05 +0100 Subject: [PATCH] Add second support in imag-diary commandline interface --- bin/domain/imag-diary/src/create.rs | 40 ++++++++++++++++++++++++----- bin/domain/imag-diary/src/ui.rs | 12 ++++++--- bin/domain/imag-diary/src/util.rs | 3 +++ doc/src/09020-changelog.md | 1 + 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs index 823f35cd..9c780cb2 100644 --- a/bin/domain/imag-diary/src/create.rs +++ b/bin/domain/imag-diary/src/create.rs @@ -65,13 +65,14 @@ fn create_entry<'a>(diary: &'a Store, diaryname: &str, rt: &Runtime) -> FileLock let create_timed = create.value_of("timed") .map(|t| parse_timed_string(t, diaryname).map_err_trace_exit_unwrap(1)) .map(Some) - .unwrap_or_else(|| match get_diary_timed_config(rt, diaryname) { - Err(e) => trace_error_exit(&e, 1), - Ok(Some(t)) => Some(t), - Ok(None) => { - warn!("Missing config: 'diary.diaries.{}.timed'", diaryname); - warn!("Assuming 'false'"); - None + .unwrap_or_else(|| { + match get_diary_timed_config(rt, diaryname).map_err_trace_exit_unwrap(1) { + Some(t) => Some(t), + None => { + warn!("Missing config: 'diary.diaries.{}.timed'", diaryname); + warn!("Assuming 'false'"); + None + } } }); @@ -135,6 +136,31 @@ fn create_id_from_clispec(create: &ArgMatches, diaryname: &str, timed_type: Time time.with_minute(min) }, + + Timed::Secondly => { + let time = get_hourly_id(create); + let min = create + .value_of("minute") + .map(|m| { debug!("minute = {:?}", m); m }) + .and_then(|s| { + FromStr::from_str(s) + .map_err(|_| warn!("Could not parse minute: '{}'", s)) + .ok() + }) + .unwrap_or(time.minute()); + + let sec = create + .value_of("second") + .map(|s| { debug!("second = {:?}", s); s }) + .and_then(|s| { + FromStr::from_str(s) + .map_err(|_| warn!("Could not parse second: '{}'", s)) + .ok() + }) + .unwrap_or(time.second()); + + time.with_minute(min).with_second(sec) + }, } } diff --git a/bin/domain/imag-diary/src/ui.rs b/bin/domain/imag-diary/src/ui.rs index 91712fb6..b111412e 100644 --- a/bin/domain/imag-diary/src/ui.rs +++ b/bin/domain/imag-diary/src/ui.rs @@ -43,9 +43,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .short("t") .takes_value(true) .required(false) - .help("By default, one entry is created per day. With --timed=h[ourly] or - --timed=m[inutely] one can create per-hour and per-minute entries (more like - a microblog then")) + .help("By default, one entry is created per day. With --timed=h[ourly] or --timed=m[inutely] one can create per-hour and per-minute entries (more like a microblog then")) .arg(Arg::with_name("hour") .long("hour") @@ -57,6 +55,11 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .takes_value(true) .required(false) .help("When using --timed, override the minute component")) + .arg(Arg::with_name("second") + .long("second") + .takes_value(true) + .required(false) + .help("When using --timed, override the second component")) // When using --hour or --minute, --timed must be present .group(ArgGroup::with_name("timing-hourly") @@ -65,6 +68,9 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .group(ArgGroup::with_name("timing-minutely") .args(&["minute"]) .requires("timed")) + .group(ArgGroup::with_name("timing-secondly") + .args(&["second"]) + .requires("timed")) ) .subcommand(SubCommand::with_name("edit") diff --git a/bin/domain/imag-diary/src/util.rs b/bin/domain/imag-diary/src/util.rs index 40811c60..4aaa81e0 100644 --- a/bin/domain/imag-diary/src/util.rs +++ b/bin/domain/imag-diary/src/util.rs @@ -33,6 +33,7 @@ pub fn get_diary_name(rt: &Runtime) -> Option { pub enum Timed { Hourly, Minutely, + Secondly, } /// Returns true if the diary should always create timed entries, which is whenever @@ -76,6 +77,8 @@ pub fn parse_timed_string(s: &str, diary_name: &str) -> Result { Ok(Timed::Hourly) } else if s == "m" || s == "minutely" { Ok(Timed::Minutely) + } else if s == "s" || s == "secondly" { + Ok(Timed::Secondly) } else { let s = format!("Cannot parse config: 'diary.diaries.{}.timed = {}'", diary_name, s); diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index 7d59b060..3e3340c5 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -32,6 +32,7 @@ This section contains the changelog from the last release to the next release. * `libimagentryutil` was introduced, a library for helpers for `libimagstore::store::Entry` handling and writing extension-writing. * `imag-edit` was introduced + * `imag-diary` got second-granularity support in the CLI. * Minor changes * Internals were refactored from `match`ing all the things into function chaining