summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-09 18:38:12 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-11-09 18:38:12 +0100
commitead9438c412c6f14fc6f3d77fb88ca40a7634452 (patch)
tree5436297c0c82e7621d4bda64021539db0d4dc11f
parent01db294700a594b9b004855097b3bcfee9946d61 (diff)
parent7873d99df51762c795589da66348e21bb74cfb5f (diff)
Merge branch 'libimagtodo-req-rewrite' into master
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/domain/imag-todo/Cargo.toml18
-rw-r--r--bin/domain/imag-todo/etc/on-add.sh4
-rw-r--r--bin/domain/imag-todo/etc/on-modify.sh4
-rw-r--r--bin/domain/imag-todo/src/lib.rs449
-rw-r--r--bin/domain/imag-todo/src/ui.rs183
-rw-r--r--doc/src/05100-lib-todo.md63
-rw-r--r--lib/domain/libimagtodo/Cargo.toml32
-rw-r--r--lib/domain/libimagtodo/src/entry.rs138
-rw-r--r--lib/domain/libimagtodo/src/iter.rs114
-rw-r--r--lib/domain/libimagtodo/src/lib.rs44
-rw-r--r--lib/domain/libimagtodo/src/priority.rs68
-rw-r--r--lib/domain/libimagtodo/src/status.rs72
-rw-r--r--lib/domain/libimagtodo/src/store.rs152
-rw-r--r--lib/domain/libimagtodo/src/task.rs45
-rw-r--r--lib/domain/libimagtodo/src/taskstore.rs184
15 files changed, 1105 insertions, 465 deletions
diff --git a/bin/domain/imag-todo/Cargo.toml b/bin/domain/imag-todo/Cargo.toml
index 12a2719a..f1e8dc91 100644
--- a/bin/domain/imag-todo/Cargo.toml
+++ b/bin/domain/imag-todo/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-authors = ["mario <mario-krehl@gmx.de>"]
+authors = ["Matthias Beyer <mail@beyermatthias.de>"]
name = "imag-todo"
version = "0.10.0"
@@ -25,10 +25,18 @@ toml = "0.5.1"
toml-query = "0.9.2"
is-match = "0.1.0"
failure = "0.1.5"
-
-libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
-libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
-libimagtodo = { version = "0.10.0", path = "../../../lib/domain/libimagtodo" }
+chrono = "0.4"
+filters = "0.3"
+kairos = "0.3"
+resiter = "0.4.0"
+
+libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
+libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
+libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
+libimagentryedit = { version = "0.10.0", path = "../../../lib/entry/libimagentryedit" }
+libimagtodo = { version = "0.10.0", path = "../../../lib/domain/libimagtodo" }
+libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" }
+libimagentryview = { version = "0.10.0", path = "../../../lib/entry/libimagentryview" }
[dependencies.clap]
version = "2.33.0"
diff --git a/bin/domain/imag-todo/etc/on-add.sh b/bin/domain/imag-todo/etc/on-add.sh
deleted file mode 100644
index a58e4989..00000000
--- a/bin/domain/imag-todo/etc/on-add.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#/!usr/bin/env bash
-
-imag todo tw-hook --add
-
diff --git a/bin/domain/imag-todo/etc/on-modify.sh b/bin/domain/imag-todo/etc/on-modify.sh
deleted file mode 100644
index 89be96d0..00000000
--- a/bin/domain/imag-todo/etc/on-modify.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#/!usr/bin/env bash
-
-imag todo tw-hook --delete
-
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index 16f42262..f6598a7f 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -35,30 +35,48 @@
)]
extern crate clap;
-#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
-#[macro_use] extern crate is_match;
-extern crate failure;
+extern crate chrono;
+extern crate filters;
+extern crate kairos;
+#[macro_use] extern crate log;
+#[macro_use] extern crate failure;
+extern crate resiter;
extern crate libimagrt;
+extern crate libimagstore;
extern crate libimagerror;
+extern crate libimagentryedit;
extern crate libimagtodo;
+extern crate libimagutil;
+extern crate libimagentryview;
-use std::process::{Command, Stdio};
-use std::io::stdin;
use std::io::Write;
+use std::result::Result as RResult;
+
+use clap::ArgMatches;
+use chrono::NaiveDateTime;
use failure::Error;
use failure::Fallible as Result;
+use failure::err_msg;
use clap::App;
+use resiter::AndThen;
+use resiter::IterInnerOkOrElse;
-use libimagrt::runtime::Runtime;
+use libimagentryedit::edit::Edit;
+use libimagentryview::viewer::ViewFromIter;
+use libimagentryview::viewer::Viewer;
use libimagrt::application::ImagApplication;
-use libimagtodo::taskstore::TaskStore;
-use libimagerror::trace::{MapErrTrace, trace_error};
-use libimagerror::iter::TraceIterator;
-use libimagerror::exit::ExitUnwrap;
-use libimagerror::io::ToExitCode;
+use libimagrt::runtime::Runtime;
+use libimagstore::iter::get::*;
+use libimagstore::store::Entry;
+use libimagstore::store::FileLockEntry;
+use libimagtodo::entry::Todo;
+use libimagtodo::priority::Priority;
+use libimagtodo::status::Status;
+use libimagtodo::store::TodoStore;
+use libimagutil::date::datetime_to_string;
mod ui;
@@ -70,21 +88,20 @@ pub enum ImagTodo {}
impl ImagApplication for ImagTodo {
fn run(rt: Runtime) -> Result<()> {
match rt.cli().subcommand_name() {
- Some("tw-hook") => tw_hook(&rt),
- Some("list") => list(&rt),
- Some(other) => {
+ Some("create") => create(&rt),
+ Some("show") => show(&rt),
+ Some("mark") => mark(&rt),
+ Some("pending") | None => list_todos(&rt, &StatusMatcher::new().is(Status::Pending), false),
+ Some("list") => list(&rt),
+ Some(other) => {
debug!("Unknown command");
- let _ = rt.handle_unknown_subcommand("imag-todo", other, rt.cli())
- .map_err_trace_exit_unwrap()
- .code()
- .map(::std::process::exit);
+ if rt.handle_unknown_subcommand("imag-todo", other, rt.cli())?.success() {
+ Ok(())
+ } else {
+ Err(err_msg("Failed to handle unknown subcommand"))
+ }
}
- None => {
- warn!("No command");
- },
- };
-
- Ok(())
+ } // end match scmd
}
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
@@ -104,99 +121,311 @@ impl ImagApplication for ImagTodo {
}
}
-fn tw_hook(rt: &Runtime) {
- let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap();
- if subcmd.is_present("add") {
- let stdin = stdin();
-
- // implements BufRead which is required for `Store::import_task_from_reader()`
- let stdin = stdin.lock();
-
- let (_, line, uuid ) = rt
- .store()
- .import_task_from_reader(stdin)
- .map_err_trace_exit_unwrap();
-
- writeln!(rt.stdout(), "{}\nTask {} stored in imag", line, uuid)
- .to_exit_code()
- .unwrap_or_exit();
-
- } else if subcmd.is_present("delete") {
- // The used hook is "on-modify". This hook gives two json-objects
- // per usage und wants one (the second one) back.
- let stdin = stdin();
- rt.store().delete_tasks_by_imports(stdin.lock()).map_err_trace().ok();
- } else {
- // Should not be possible, as one argument is required via
- // ArgGroup
- unreachable!();
+/// A black- and whitelist for matching statuses of todo entries
+///
+/// The blacklist is checked first, followed by the whitelist.
+/// In case the whitelist is empty, the StatusMatcher works with a
+/// blacklist-only approach.
+#[derive(Debug)]
+pub struct StatusMatcher {
+ is: Vec<Status>,
+ is_not: Vec<Status>,
+}
+
+impl StatusMatcher {
+ pub fn new() -> Self {
+ StatusMatcher {
+ is: Vec::new(),
+ is_not: Vec::new(),
+ }
+ }
+
+ pub fn is(mut self, s: Status) -> Self {
+ self.add_is(s);
+ self
+ }
+
+ pub fn add_is(&mut self, s: Status) {
+ self.is.push(s);
+ }
+
+ pub fn is_not(mut self, s: Status) -> Self {
+ self.add_is_not(s);
+ self
+ }
+
+ pub fn add_is_not(&mut self, s: Status) {
+ self.is_not.push(s);
+ }
+
+ pub fn matches(&self, todo: Status) -> bool {
+ if self.is_not.iter().find(|t| **t == todo).is_some() {
+ // On blacklist
+ false
+ } else if self.is.len() < 1 || self.is.iter().find(|t| **t == todo).is_some() {
+ // No whitelist or on whitelist
+ true
+ } else {
+ // Not on blacklist, but whitelist exists and not on it either
+ false
+ }
+ }
+}
+
+fn create(rt: &Runtime) -> Result<()> {
+ debug!("Creating todo");
+ let scmd = rt.cli().subcommand().1.unwrap(); // safe by clap
+
+ let scheduled: Option<NaiveDateTime> = get_datetime_arg(&scmd, "create-scheduled")?;
+ let hidden: Option<NaiveDateTime> = get_datetime_arg(&scmd, "create-hidden")?;
+ let due: Option<NaiveDateTime> = get_datetime_arg(&scmd, "create-due")?;
+ let prio: Option<Priority> = scmd.value_of("create-prio").map(prio_from_str).transpose()?;
+ let status: Status = scmd.value_of("create-status").map(Status::from_str).unwrap()?;
+ let edit = scmd.is_present("create-edit");
+ let text = scmd.value_of("text").unwrap();
+
+ trace!("Creating todo with these variables:");
+ trace!("scheduled = {:?}", scheduled);
+ trace!("hidden = {:?}", hidden);
+ trace!("due = {:?}", due);
+ trace!("prio = {:?}", prio);
+ trace!("status = {:?}", status);
+ trace!("edit = {}", edit);
+ trace!("text = {:?}", text);
+
+ let mut entry = rt.store().create_todo(status, scheduled, hidden, due, prio, true)?;
+ debug!("Created: todo {}", entry.get_uuid()?);
+
+ debug!("Setting content");
+ *entry.get_content_mut() = text.to_string();
+
+ if edit {
+ debug!("Editing content");
+ entry.edit_content(&rt)?;
+ }
+
+ rt.report_touched(entry.get_location()).map_err(Error::from)
+}
+
+fn mark(rt: &Runtime) -> Result<()> {
+ fn mark_todos_as(rt: &Runtime, status: Status) -> Result<()> {
+ rt.ids::<crate::ui::PathProvider>()?
+ .ok_or_else(|| err_msg("No ids supplied"))?
+ .into_iter()
+ .map(Ok)
+ .into_get_iter(rt.store())
+ .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
+ .and_then_ok(|mut e| e.set_status(status.clone()))
+ .collect()
+ }
+
+ let scmd = rt.cli().subcommand().1.unwrap();
+ match scmd.subcommand_name() {
+ Some("done") => mark_todos_as(rt, Status::Done),
+ Some("delete") => mark_todos_as(rt, Status::Deleted),
+ Some("pending") => mark_todos_as(rt, Status::Pending),
+ Some(other) => Err(format_err!("Unknown mark type selected: {}", other)),
+ None => Err(format_err!("No mark type selected, doing nothing!")),
}
}
-fn list(rt: &Runtime) {
- use toml_query::read::TomlValueReadTypeExt;
+/// Generic todo listing function
+///
+/// Supports filtering of todos by status using the passed in StatusMatcher
+fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Result<()> {
+ use filters::failable::filter::FailableFilter;
+ debug!("Listing todos with status filter {:?}", matcher);
- let subcmd = rt.cli().subcommand_matches("list").unwrap();
- let verbose = subcmd.is_present("verbose");
+ let now = {
+ let now = chrono::offset::Local::now();
+ NaiveDateTime::new(now.date().naive_local(), now.time())
+ };
- // Helper for toml_query::read::TomlValueReadExt::read() return value, which does only
- // return Result<T> instead of Result<Option<T>>, which is a real inconvenience.
- //
- let no_identifier = |e: &::toml_query::error::Error| -> bool {
- is_match!(e, &::toml_query::error::Error::IdentifierNotFoundInDocument(_))
+ let filter_hidden = |todo: &FileLockEntry<'_>| -> Result<bool> {
+ Ok(todo.get_hidden()?.map(|hid| hid > now).unwrap_or(true))
};
- let res = rt.store().all_tasks() // get all tasks
- .map(|iter| { // and if this succeeded
- // filter out the ones were we can read the uuid
- let uuids : Vec<_> = iter.trace_unwrap_exit().filter_map(|storeid| {
- match rt.store().retrieve(storeid) {
- Ok(fle) => {
- match fle.get_header().read_string("todo.uuid") {
- Ok(Some(ref u)) => Some(u.clone()),
- Ok(None) => {
- error!("Header missing field in {}", fle.get_location());
- None
- },
- Err(e) => {
- if !no_identifier(&e) {
- trace_error(&Error::from(e));
- }
- None
- }
- }
- },
- Err(e) => {
- trace_error(&e);
- None
- },
+ struct TodoViewer {
+ details: bool,
+ }
+ impl Viewer for TodoViewer {
+ fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error>
+ where W: Write
+ {
+ use libimagentryview::error::Error as E;
+
+ if !entry.is_todo().map_err(E::from)? {
+ return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from);
+ }
+
+ let uuid = entry.get_uuid().map_err(E::from)?;
+ let status = entry.get_status().map_err(E::from)?;
+ let status = status.as_str();
+ let first_line = entry.get_content()
+ .lines()
+ .next()
+ .unwrap_or("<empty description>");
+
+ if !self.details {
+ writeln!(sink, "{uuid} - {status} : {first_line}",
+ uuid = uuid,
+ status = status,
+ first_line = first_line)
+ } else {
+ let sched = get_dt_str(entry.get_scheduled(), "Not scheduled")?;
+ let hidden = get_dt_str(entry.get_hidden(), "Not hidden")?;
+ let due = get_dt_str(entry.get_due(), "No due")?;
+ let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
+ .unwrap_or("No prio".to_string());
+
+ writeln!(sink, "{uuid} - {status} - {sched} - {hidden} - {due} - {prio}: {first_line}",
+ uuid = uuid,
+ status = status,
+ sched = sched,
+ hidden = hidden,
+ due = due,
+ prio = priority,
+ first_line = first_line)
+ }
+ .map_err(libimagentryview::error::Error::from)
+ }
+ }
+
+ let viewer = TodoViewer { details: false };
+
+ rt.store()
+ .get_todos()?
+ .into_get_iter()
+ .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .filter_map(|r| {
+ match r.and_then(|e| e.get_status().map(|s| (s, e))) {
+ Err(e) => Some(Err(e)),
+ Ok((st, e)) => if matcher.matches(st) {
+ Some(Ok(e))
+ } else {
+ None
}
- })
- .collect();
-
- // compose a `task` call with them, ...
- let outstring = if verbose { // ... if verbose
- let output = Command::new("task")
- .stdin(Stdio::null())
- .args(&uuids)
- .spawn()
- .unwrap_or_else(|e| {
- error!("Failed to execute `task` on the commandline: {:?}. I'm dying now.", e);
- ::std::process::exit(1)
- })
- .wait_with_output()
- .unwrap_or_else(|e| panic!("failed to unwrap output: {}", e));
-
- String::from_utf8(output.stdout)
- .unwrap_or_else(|e| panic!("failed to execute: {}", e))
- } else { // ... else just join them
- uuids.join("\n")
- };
-
- // and then print that
- writeln!(rt.stdout(), "{}", outstring).to_exit_code().unwrap_or_exit();
- });
-
- res.map_err_trace().ok();
+ }
+ })
+ .and_then_ok(|entry| {
+ if show_hidden || filter_hidden.filter(&entry)? {
+ viewer.view_entry(&entry, &mut rt.stdout())?;
+ }
+
+ rt.report_touched(entry.get_location()).map_err(Error::from)
+ })
+ .collect()
+}
+
+/// Generic todo items list function
+///
+/// This sets up filtes based on the command line and prints out a list of todos
+fn list(rt: &Runtime) -> Result<()> {
+ debug!("Listing todo");
+ let scmd = rt.cli().subcommand().1;
+ let table = scmd.map(|s| s.is_present("list-table")).unwrap_or(true);
+ let hidden = scmd.map(|s| s.is_present("list-hidden")).unwrap_or(false);
+ let done = scmd.map(|s| s.is_present("list-done")).unwrap_or(false);
+ let nopending = scmd.map(|s| s.is_present("list-nopending")).unwrap_or(true);
+
+ trace!("table = {}", table);
+ trace!("hidden = {}", hidden);
+ trace!("done = {}", done);
+ trace!("nopending = {}", nopending);
+
+ let mut matcher = StatusMatcher::new();
+ if !done { matcher.add_is_not(Status::Done); }
+ if nopending { matcher.add_is_not(Status::Pending); }
+
+ // TODO: Support printing as ASCII table
+ list_todos(rt, &matcher, hidden)
+}
+
+fn show(rt: &Runtime) -> Result<()> {
+ #[derive(Default)]
+ struct TodoShow;
+ impl Viewer for TodoShow {
+
+ fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error>
+ where W: Write
+ {
+ use libimagentryview::error::Error as E;
+
+ if !entry.is_todo().map_err(E::from)? {
+ return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from);
+ }
+
+ let uuid = entry.get_uuid().map_err(E::from)?;
+ let status = entry.get_status().map_err(E::from)?;
+ let status = status.as_str();
+ let text = entry.get_content();
+ let sched = get_dt_str(entry.get_scheduled(), "Not scheduled")?;
+ let hidden = get_dt_str(entry.get_hidden(), "Not hidden")?;
+ let due = get_dt_str(entry.get_due(), "No due")?;
+ let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
+ .unwrap_or("No prio".to_string());
+
+ writeln!(sink, "{uuid}\nStatus: {status}\nPriority: {prio}\nScheduled: {sched}\nHidden: {hidden}\nDue: {due}\n\n{text}",
+ uuid = uuid,
+ status = status,
+ sched = sched,
+ hidden = hidden,
+ due = due,
+ prio = priority,
+ text = text)
+ .map_err(Error::from)
+ .map_err(libimagentryview::error::Error::from)
+ }
+ }
+
+ rt.ids::<crate::ui::PathProvider>()?
+ .ok_or_else(|| err_msg("No ids supplied"))?
+ .into_iter()
+ .map(Ok)
+ .into_get_iter(rt.store())
+ .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
+ .collect::<Result<Vec<_>>>()?
+ .into_iter()
+ .view::<TodoShow, _>(&mut rt.stdout())
+ .map_err(Error::from)
+}
+
+//
+// utility functions
+//
+
+fn get_datetime_arg(scmd: &ArgMatches, argname: &'static str) -> Result<Option<NaiveDateTime>> {
+ use kairos::timetype::TimeType;
+ use kairos::parser;
+
+ match scmd.value_of(argname) {
+ None => Ok(None),
+ Some(v) => match parser::parse(v)? {
+ parser::Parsed::TimeType(TimeType::Moment(moment)) => Ok(Some(moment)),
+ parser::Parsed::TimeType(other) => {
+ Err(format_err!("You did not pass a date, but a {}", other.name()))
+ },
+ parser::Parsed::Iterator(_) => {
+ Err(format_err!("Argument {} results in a list of dates, but we need a single date.", v))
+ }
+ }
+ }
+}
+
+fn prio_from_str<S: AsRef<str>>(s: S) -> Result<Priority> {
+ match s.as_ref() {
+ "h" => Ok(Priority::High),
+ "m" => Ok(Priority::Medium),
+ "l" => Ok(Priority::Low),
+ other => Err(format_err!("Unsupported Priority: '{}'", other)),
+ }
+}
+
+fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> RResult<String, libimagentryview::error::Error> {
+ Ok(d.map_err(libimagentryview::error::Error::from)?
+ .map(|v| datetime_to_string(&v))
+ .unwrap_or(s.to_string()))
}
diff --git a/bin/domain/imag-todo/src/ui.rs b/bin/domain/imag-todo/src/ui.rs
index 073508cf..3299b7de 100644
--- a/bin/domain/imag-todo/src/ui.rs
+++ b/bin/domain/imag-todo/src/ui.rs
@@ -17,45 +17,184 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use clap::{Arg, App, ArgGroup, SubCommand};
+use std::path::PathBuf;
+use clap::{Arg, ArgMatches, App, SubCommand};
+use failure::Fallible as Result;
+
+use libimagstore::storeid::StoreId;
+use libimagstore::storeid::IntoStoreId;
+use libimagrt::runtime::IdPathProvider;
+
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
- .subcommand(SubCommand::with_name("tw-hook")
- .about("For use in a taskwarrior hook")
+ .subcommand(SubCommand::with_name("create")
+ .about("Create task")
.version("0.1")
- .arg(Arg::with_name("add")
- .long("add")
- .short("a")
- .takes_value(false)
+ .arg(Arg::with_name("create-scheduled")
+ .long("scheduled")
+ .short("s")
+ .takes_value(true)
.required(false)
- .help("For use in an on-add hook"))
+ .help("Set a 'scheduled' date/time")
+ )
+
+ .arg(Arg::with_name("create-hidden")
+ .long("hidden")
+ .short("h")
+ .takes_value(true)
+ .required(false)
+ .help("Set a 'hidden' date/time")
+ )
- .arg(Arg::with_name("delete")
- .long("delete")
+ .arg(Arg::with_name("create-due")
+ .long("due")
.short("d")
+ .takes_value(true)
+ .required(false)
+ .help("Set a 'due' date/time")
+ )
+
+ .arg(Arg::with_name("create-prio")
+ .long("prio")
+ .short("p")
+ .takes_value(true)
+ .required(false)
+ .help("Set a priority")
+ .possible_values(&["h", "m", "l"])
+ )
+
+ .arg(Arg::with_name("create-status")
+ .long("status")
+ .takes_value(true)
+ .required(false)
+ .help("Set a status, useful if the task is already done")
+ .default_value("pending")
+ .possible_values(&["pending", "done", "deleted"])
+ )
+
+ .arg(Arg::with_name("create-edit")
+ .long("edit")
+ .short("e")
.takes_value(false)
.required(false)
- .help("For use in an on-delete hook"))
+ .help("Create and then edit the entry")
+ )
+
+ .arg(Arg::with_name("text")
+ .index(1)
+ .multiple(true)
+ .required(true)
+ .help("Text for the todo")
+ )
+ )
- .group(ArgGroup::with_name("taskwarrior hooks")
- .args(&[ "add",
- "delete",
- ])
- .required(true))
+ .subcommand(SubCommand::with_name("pending")
+ .arg(Arg::with_name("todos")
+ .index(1)
+ .takes_value(true)
+ .required(false)
+ .help("List pending todos (same as 'list' command without arguments)")
+ )
)
.subcommand(SubCommand::with_name("list")
- .about("List all tasks")
+ .about("List tasks (default)")
.version("0.1")
- .arg(Arg::with_name("verbose")
- .long("verbose")
- .short("v")
+ .arg(Arg::with_name("list-table")
+ .long("table")
+ .short("T")
.takes_value(false)
.required(false)
- .help("Asks taskwarrior for all the details")
+ .help("Print a nice ascii-table")
)
- )
+
+ .arg(Arg::with_name("list-hidden")
+ .long("hidden")
+ .short("H")
+ .takes_value(false)
+ .required(false)
+ .help("Print also hidden todos")
+ )
+
+ .arg(Arg::with_name("list-done")
+ .long("done")
+ .short("D")
+ .takes_value(false)
+ .required(false)
+ .help("Print also done todos")
+ )
+
+ .arg(Arg::with_name("list-nopending")
+ .long("no-pending")
+ .short("P")
+ .takes_value(false)
+ .required(false)
+ .help("Do not print pending tasks")
+ )
+
+ )
+
+ .subcommand(SubCommand::with_name("show")
+ .arg(Arg::with_name("todos")
+ .index(1)
+ .takes_value(true)
+ .required(false)
+ .help("Show the passed todos")
+ )
+ )
+
+ .subcommand(SubCommand::with_name("mark")
+ .about("Mark tasks as pending, done or deleted")
+ .version("0.1")
+
+ .subcommand(SubCommand::with_name("pending")
+ .arg(Arg::with_name("todos")
+ .index(1)
+ .takes_value(true)
+ .required(false)
+ .help("List pending todos (same as 'list' command without arguments)")
+ )
+ )
+
+ .subcommand(SubCommand::with_name("done")
+ .arg(Arg::with_name("todos")
+ .index(1)
+ .takes_value(true)
+ .required(false)
+ .help("Mark the passed todos as done")
+ )
+ )
+
+ .subcommand(SubCommand::with_name("deleted")
+ .arg(Arg::with_name("todos")
+ .index(1)
+ .takes_value(true)
+ .required(false)
+ .help("Mark the passed todos as deleted")
+ )
+ )
+ )
+
}
+
+pub struct PathProvider;
+impl IdPathProvider for PathProvider {
+ fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> {
+ match matches.subcommand() {
+ ("show", Some(scmd)) => scmd.values_of("todos"),
+ ("show", None) => unimplemented!(),
+ _ => unimplemented!()
+ }
+ .map(|v| v
+ .into_iter()
+ .map(PathBuf::from)
+ .map(|pb| pb.into_storeid())
+ .collect::<Result<Vec<_>>>()
+ )
+ .transpose()
+ }
+}
+
diff --git a/doc/src/05100-lib-todo.md b/doc/src/05100-lib-todo.md
index 50eedb41..84fe851d 100644
--- a/doc/src/05100-lib-todo.md
+++ b/doc/src/05100-lib-todo.md
@@ -3,42 +3,43 @@
The library for the todo module which provides functionality to
implement/implements a todomanager in imag.
+
### Implementation details
-One todo entry is stored as one imag entry. The ID of the imag entry is generated by
-appending a unique ID (UUID) to "todo/".
+One todo entry is stored as one imag entry. The ID of the imag entry is
+generated by appending a unique ID (UUID) to "todo/".
The unique ID identifies the todo entry.
+
#### Stored data
A todo entry stores the following information:
* The (UU)ID of the todo entry
* A status of the todo entry. Valid values are: "deleted", "done", "pending"
-* A "scheduled" date/datetime, can also yield an iterator
+* An optional "scheduled" date/datetime
* An optional "hidden" value, which specifies a date in the future where this
- todo entry should show up. Relative (eg. "-5days"),
- to the "scheduled" date/datetime
-* An optional "due" date/datetime, relative to the "scheduled" time
-* A list of dependencies of the entry
-* A "importance"-level, config file defined (strings in an array, index used for
- ranking them)
-* User defined value (a map of key-value string pairs)
+ todo entry should show up.
+* An optional "due" date/datetime
+* A "priority"-level, either "h", "m", "l"
The description of the todo entry is stored as plain text.
+
#### Data not stored
Some data is explicitely _not_ stored by the library because there are other
libraries fullfilling that purpose. These are:
+* Related todos, which can be done via libimagentrylink
* Tags, which can be done with libimagentrytag
* Category, which can be done with libimagentrycategory
* Project belonging, which can be done with libimagentrylink (by linking to a
project file - note that "project" is a domain not yet implemented by imag)
* Annotations, which can be stored with libimagentryannotation
+
#### Header format
The header partial for libimagtodo is as follows:
@@ -46,42 +47,24 @@ The header partial for libimagtodo is as follows:
```
[todo]
uuid = "string"
-status = "string"
-scheduled = "<kairos time spec>"
-hidden = "<kairos time func (optional)>"
-due = "<kairos time func (optional)>"
-depends = [ "list of uuids" ]
-importance = "string"
-uda = {}
+status = "enum { 'deleted', 'done', 'pending' }"
+scheduled = "<NaiveDateTime>" // optional
+hidden = "<NaiveDateTime>" // optional
+due = "<NaiveDateTime>" // optional
+priority = "enum { 'h', 'm', 'l' }" // optional
```
+
#### Functionality
The provided functionality of this library includes, but is not limited to:
-* Creating new todo entries in the store
-* Deleting todo entries from the store
-* get/retrieving todo entries from the store
-* Turning an entry into a todo entry
-* Getting todo details from an entry
- * scheduled, due, waiting date/datetime
- * priority