summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-05 16:20:50 +0100
committerGitHub <noreply@github.com>2018-02-05 16:20:50 +0100
commit3a54fc220c8eae533a415068729d347b9a8b5908 (patch)
tree0327578ada073975cac18b8b63db5c615636681f
parent1d4015dc9c5b9d3a761f62b1efe319f484b77259 (diff)
parentd1fc8c3995cb5464742d3c138078ec65db4cd7bc (diff)
downloadimag-3a54fc220c8eae533a415068729d347b9a8b5908.zip
imag-3a54fc220c8eae533a415068729d347b9a8b5908.tar.gz
Merge pull request #1229 from matthiasbeyer/imag-diary/timed-seconds
imag-diary: Add second granularity support
-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
-rw-r--r--doc/src/09020-changelog.md1
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 823f35c..9c780cb 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 91712fb..b111412 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 40811c6..4aaa81e 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);
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 7d59b06..3e3340c 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