summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-04 19:50:05 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-02-04 19:51:07 +0100
commitd1fc8c3995cb5464742d3c138078ec65db4cd7bc (patch)
tree0327578ada073975cac18b8b63db5c615636681f /bin
parent1d4015dc9c5b9d3a761f62b1efe319f484b77259 (diff)
Add second support in imag-diary commandline interface
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-diary/src/create.rs40
-rw-r--r--bin/domain/imag-diary/src/ui.rs12
-rw-r--r--bin/domain/imag-diary/src/util.rs3
3 files changed, 45 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<String> {
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<Timed> {
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);