diff --git a/cli/src/cmd/shared.rs b/cli/src/cmd/shared.rs index 6ae2ff4a3..474bca280 100644 --- a/cli/src/cmd/shared.rs +++ b/cli/src/cmd/shared.rs @@ -1,6 +1,7 @@ use clap::Arg; use failure::{format_err, Fallible}; -use std::path::Path; +use std::env; +use std::ffi::OsString; use taskchampion::{server, taskstorage, Replica, Task, Uuid}; pub(super) fn task_arg<'a>() -> Arg<'a, 'a> { @@ -46,14 +47,18 @@ impl CommandInvocation { // -- utilities for command invocations pub(super) fn get_replica(&self) -> Replica { - Replica::new(Box::new( - taskstorage::KVStorage::new(Path::new("/tmp/tasks")).unwrap(), - )) + // temporarily use $TASK_DB to locate the taskdb + let taskdb_dir = env::var_os("TASK_DB").unwrap_or_else(|| OsString::from("/tmp/tasks")); + Replica::new(Box::new(taskstorage::KVStorage::new(taskdb_dir).unwrap())) } pub(super) fn get_server(&self) -> Fallible { + // temporarily use $SYNC_SERVER_ORIGIN for the sync server + let sync_server_origin = env::var_os("SYNC_SERVER_ORIGIN") + .map(|osstr| osstr.into_string().unwrap()) + .unwrap_or_else(|| String::from("http://localhost:8080")); Ok(server::RemoteServer::new( - "http://localhost:8080".into(), + sync_server_origin, Uuid::parse_str("d5b55cbd-9a82-4860-9a39-41b67893b22f").unwrap(), )) } diff --git a/docs/src/usage.md b/docs/src/usage.md index e284815bd..b16c724e1 100644 --- a/docs/src/usage.md +++ b/docs/src/usage.md @@ -1,6 +1,20 @@ # Usage +## `task` + The main interface to your tasks is the `task` command, which supports various subcommands. You can find a quick list of all subcommands with `task help`. Note that the `task` interface does not match that of TaskWarrior. + +### Configuration + +Temporarily, configuration is by environment variables. +The directory containing the replica's task data is given by `TASK_DB`, defaulting to `/tmp/tasks`. +the origin of the sync server is given by `SYNC_SERVER_ORIGIN`, defaulting to `http://localhost:8080`. + +## `taskchampion-sync-server` + +Run `taskchampion-sync-server` to start the sync server. +It serves on port 8080 on all interfaces, using an in-memory database (meaning that all data is lost when the process exits). +Requests for previously-unknown clients are automatically added. diff --git a/taskchampion/src/taskstorage/kv.rs b/taskchampion/src/taskstorage/kv.rs index 87d8416c3..5e1cfde41 100644 --- a/taskchampion/src/taskstorage/kv.rs +++ b/taskchampion/src/taskstorage/kv.rs @@ -23,7 +23,7 @@ const NEXT_OPERATION: u64 = 2; const NEXT_WORKING_SET_INDEX: u64 = 3; impl<'t> KVStorage<'t> { - pub fn new(directory: &Path) -> Fallible { + pub fn new>(directory: P) -> Fallible> { let mut config = Config::default(directory); config.bucket("tasks", None); config.bucket("numbers", None);