Add second support in imag-diary commandline interface
This commit is contained in:
parent
1d4015dc9c
commit
d1fc8c3995
4 changed files with 46 additions and 10 deletions
|
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue