add a 'task sync' command using a copy of the test server
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use clap::Arg;
|
||||
use failure::{format_err, Fallible};
|
||||
use taskchampion::{Replica, Task, Uuid};
|
||||
use std::path::Path;
|
||||
use taskchampion::{server, taskstorage, Replica, Task, Uuid};
|
||||
|
||||
pub(super) fn task_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("task")
|
||||
@@ -26,3 +27,31 @@ pub(super) fn get_task<S: AsRef<str>>(replica: &mut Replica, task_arg: S) -> Fal
|
||||
|
||||
Err(format_err!("Cannot interpret {:?} as a task", task_arg))
|
||||
}
|
||||
|
||||
/// A command invocation contains all of the necessary regarding a single invocation of the CLI.
|
||||
#[derive(Debug)]
|
||||
pub struct CommandInvocation {
|
||||
pub(crate) subcommand: Box<dyn super::SubCommandInvocation>,
|
||||
}
|
||||
|
||||
impl CommandInvocation {
|
||||
pub(crate) fn new(subcommand: Box<dyn super::SubCommandInvocation>) -> Self {
|
||||
Self { subcommand }
|
||||
}
|
||||
|
||||
pub fn run(self) -> Fallible<()> {
|
||||
self.subcommand.run(&self)
|
||||
}
|
||||
|
||||
// -- utilities for command invocations
|
||||
|
||||
pub(super) fn get_replica(&self) -> Replica {
|
||||
Replica::new(Box::new(
|
||||
taskstorage::KVStorage::new(Path::new("/tmp/tasks")).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) fn get_server(&self) -> impl server::Server {
|
||||
server::LocalServer::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user