reorganize into separate crates

- taskchampion -- core implementation of a replica
 - taskchampion-cli -- command-line interface
 - taskchampion-sync-server -- server implementation (not much yet!)
This commit is contained in:
Dustin J. Mitchell 2020-11-23 14:08:42 -05:00
parent 2830043e13
commit 779a331003
36 changed files with 349 additions and 154 deletions

10
cli/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "taskchampion-cli"
version = "0.1.0"
authors = ["Dustin J. Mitchell <dustin@mozilla.com>"]
edition = "2018"
[dependencies]
clap = "~2.33.0"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
taskchampion = { path = "../taskchampion" }

62
cli/src/main.rs Normal file
View file

@ -0,0 +1,62 @@
use clap::{App, Arg, SubCommand};
use std::path::Path;
use taskchampion::{taskstorage, Replica, Status, DB};
use uuid::Uuid;
fn main() {
let matches = App::new("Rask")
.version("0.1")
.author("Dustin J. Mitchell <dustin@v.igoro.us>")
.about("Replacement for TaskWarrior")
.subcommand(
SubCommand::with_name("add").about("adds a task").arg(
Arg::with_name("description")
.help("task description")
.required(true),
),
)
.subcommand(SubCommand::with_name("list").about("lists tasks"))
.subcommand(SubCommand::with_name("pending").about("lists pending tasks"))
.subcommand(SubCommand::with_name("gc").about("run garbage collection"))
.get_matches();
let mut replica = Replica::new(
DB::new(Box::new(
taskstorage::KVStorage::new(Path::new("/tmp/tasks")).unwrap(),
))
.into(),
);
match matches.subcommand() {
("add", Some(matches)) => {
let uuid = Uuid::new_v4();
replica
.new_task(
uuid,
Status::Pending,
matches.value_of("description").unwrap().into(),
)
.unwrap();
}
("list", _) => {
for (uuid, task) in replica.all_tasks().unwrap() {
println!("{} - {:?}", uuid, task);
}
}
("pending", _) => {
let working_set = replica.working_set().unwrap();
for i in 1..working_set.len() {
if let Some(ref task) = working_set[i] {
println!("{}: {} - {:?}", i, task.get_uuid(), task);
}
}
}
("gc", _) => {
replica.gc().unwrap();
}
("", None) => {
unreachable!();
}
_ => unreachable!(),
};
}