Merge pull request #67 from djmitche/issue58

take configuration in env vars temporarily
This commit is contained in:
Dustin J. Mitchell 2020-11-28 10:16:56 -05:00 committed by GitHub
commit b34ef34b2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View file

@ -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<impl server::Server> {
// 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(),
))
}

View file

@ -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.

View file

@ -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<KVStorage> {
pub fn new<P: AsRef<Path>>(directory: P) -> Fallible<KVStorage<'t>> {
let mut config = Config::default(directory);
config.bucket("tasks", None);
config.bucket("numbers", None);