|
|
@@ -83,8 +83,8 @@ pub enum CliTauSubCommands {
|
|
|
},
|
|
|
/// List open tasks
|
|
|
List {},
|
|
|
- /// Show task by ID
|
|
|
- Show {
|
|
|
+ /// Get task by ID
|
|
|
+ Get {
|
|
|
/// Task ID
|
|
|
id: u64,
|
|
|
},
|
|
|
@@ -113,7 +113,7 @@ pub struct CliTau {
|
|
|
/// Increase verbosity
|
|
|
#[clap(short, parse(from_occurrences))]
|
|
|
pub verbose: u8,
|
|
|
- /// Rpc address
|
|
|
+ /// Rpc address
|
|
|
#[clap(long, default_value = "127.0.0.1:8875")]
|
|
|
pub listen: SocketAddr,
|
|
|
#[clap(subcommand)]
|
|
|
@@ -230,11 +230,11 @@ async fn set_comment(url: &str, id: u64, author: &str, content: &str) -> Result<
|
|
|
request(req, url.to_string()).await
|
|
|
}
|
|
|
|
|
|
-// Show task by id.
|
|
|
-// --> {"jsonrpc": "2.0", "method": "show", "params": [task_id], "id": 1}
|
|
|
+// Get task by id.
|
|
|
+// --> {"jsonrpc": "2.0", "method": "get_by_id", "params": [task_id], "id": 1}
|
|
|
// <-- {"jsonrpc": "2.0", "result": "task", "id": 1}
|
|
|
async fn show(url: &str, id: u64) -> Result<Value> {
|
|
|
- let req = jsonrpc::request(json!("show"), json!([id]));
|
|
|
+ let req = jsonrpc::request(json!("get_by_id"), json!([id]));
|
|
|
request(req, url.to_string()).await
|
|
|
}
|
|
|
|
|
|
@@ -315,72 +315,7 @@ async fn start(options: CliTau) -> Result<()> {
|
|
|
rpc_addr,
|
|
|
json!([{"title": title, "desc": desc, "assign": assign, "project": project, "due": due, "rank": rank}]),
|
|
|
)
|
|
|
- .await?;
|
|
|
- }
|
|
|
-
|
|
|
- Some(CliTauSubCommands::List {}) => {
|
|
|
- let rep = list(rpc_addr, json!([])).await?;
|
|
|
-
|
|
|
- let mut table = Table::new();
|
|
|
- table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
|
|
- table.set_titles(row!["ID", "Title", "Project", "Assigned", "Due", "Rank"]);
|
|
|
-
|
|
|
- let mut tasks: Vec<Value> = serde_json::from_value(rep)?;
|
|
|
- tasks.sort_by(|a, b| b["rank"].as_f64().partial_cmp(&a["rank"].as_f64()).unwrap());
|
|
|
-
|
|
|
- let (max_rank, min_rank) = if !tasks.is_empty() {
|
|
|
- (
|
|
|
- serde_json::from_value(tasks[0]["rank"].clone())?,
|
|
|
- serde_json::from_value(tasks[tasks.len() - 1]["rank"].clone())?,
|
|
|
- )
|
|
|
- } else {
|
|
|
- (0.0, 0.0)
|
|
|
- };
|
|
|
-
|
|
|
- for task in tasks {
|
|
|
- let project: Vec<Value> = serde_json::from_value(task["project"].clone())?;
|
|
|
- let mut projects = String::new();
|
|
|
- for (i, _) in project.iter().enumerate() {
|
|
|
- if !projects.is_empty() {
|
|
|
- projects.push(',');
|
|
|
- }
|
|
|
- projects.push_str(project.index(i).as_str().unwrap());
|
|
|
- }
|
|
|
-
|
|
|
- let assign: Vec<Value> = serde_json::from_value(task["assign"].clone())?;
|
|
|
- let mut asgn = String::new();
|
|
|
- for (i, _) in assign.iter().enumerate() {
|
|
|
- if !asgn.is_empty() {
|
|
|
- asgn.push(',');
|
|
|
- }
|
|
|
- asgn.push_str(assign.index(i).as_str().unwrap());
|
|
|
- }
|
|
|
-
|
|
|
- let date = if task["due"].is_u64() {
|
|
|
- let due = task["due"].as_i64().unwrap();
|
|
|
- NaiveDateTime::from_timestamp(due, 0).date().format("%A %-d %B").to_string()
|
|
|
- } else {
|
|
|
- "".to_string()
|
|
|
- };
|
|
|
-
|
|
|
- let rank = task["rank"].as_f64().unwrap_or(0.0) as f32;
|
|
|
-
|
|
|
- table.add_row(Row::new(vec![
|
|
|
- Cell::new(&task["id"].to_string()),
|
|
|
- Cell::new(task["title"].as_str().unwrap()),
|
|
|
- Cell::new(&projects),
|
|
|
- Cell::new(&asgn),
|
|
|
- Cell::new(&date),
|
|
|
- if rank == max_rank {
|
|
|
- Cell::new(&rank.to_string()).style_spec("bFC")
|
|
|
- } else if rank == min_rank {
|
|
|
- Cell::new(&rank.to_string()).style_spec("Fb")
|
|
|
- } else {
|
|
|
- Cell::new(&rank.to_string()).style_spec("Fc")
|
|
|
- },
|
|
|
- ]));
|
|
|
- }
|
|
|
- table.printstd();
|
|
|
+ .await?;
|
|
|
}
|
|
|
|
|
|
Some(CliTauSubCommands::Update { id, key, value }) => {
|
|
|
@@ -439,7 +374,7 @@ async fn start(options: CliTau) -> Result<()> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Some(CliTauSubCommands::Show { id }) => {
|
|
|
+ Some(CliTauSubCommands::Get { id }) => {
|
|
|
let rep = show(rpc_addr, id).await?;
|
|
|
let due = if rep["due"].is_u64() {
|
|
|
let timestamp = rep["due"].as_i64().unwrap();
|
|
|
@@ -472,9 +407,69 @@ async fn start(options: CliTau) -> Result<()> {
|
|
|
println!("TaskInfo: {}", serde_json::to_string_pretty(&t)?);
|
|
|
}
|
|
|
|
|
|
- _ => {
|
|
|
- error!("Please run 'tau help' to see usage.");
|
|
|
- return Err(Error::MissingParams)
|
|
|
+ Some(CliTauSubCommands::List {}) | None => {
|
|
|
+ let rep = list(rpc_addr, json!([])).await?;
|
|
|
+
|
|
|
+ let mut table = Table::new();
|
|
|
+ table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
|
|
+ table.set_titles(row!["ID", "Title", "Project", "Assigned", "Due", "Rank"]);
|
|
|
+
|
|
|
+ let mut tasks: Vec<Value> = serde_json::from_value(rep)?;
|
|
|
+ tasks.sort_by(|a, b| b["rank"].as_f64().partial_cmp(&a["rank"].as_f64()).unwrap());
|
|
|
+
|
|
|
+ let (max_rank, min_rank) = if !tasks.is_empty() {
|
|
|
+ (
|
|
|
+ serde_json::from_value(tasks[0]["rank"].clone())?,
|
|
|
+ serde_json::from_value(tasks[tasks.len() - 1]["rank"].clone())?,
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ (0.0, 0.0)
|
|
|
+ };
|
|
|
+
|
|
|
+ for task in tasks {
|
|
|
+ let project: Vec<Value> = serde_json::from_value(task["project"].clone())?;
|
|
|
+ let mut projects = String::new();
|
|
|
+ for (i, _) in project.iter().enumerate() {
|
|
|
+ if !projects.is_empty() {
|
|
|
+ projects.push(',');
|
|
|
+ }
|
|
|
+ projects.push_str(project.index(i).as_str().unwrap());
|
|
|
+ }
|
|
|
+
|
|
|
+ let assign: Vec<Value> = serde_json::from_value(task["assign"].clone())?;
|
|
|
+ let mut asgn = String::new();
|
|
|
+ for (i, _) in assign.iter().enumerate() {
|
|
|
+ if !asgn.is_empty() {
|
|
|
+ asgn.push(',');
|
|
|
+ }
|
|
|
+ asgn.push_str(assign.index(i).as_str().unwrap());
|
|
|
+ }
|
|
|
+
|
|
|
+ let date = if task["due"].is_u64() {
|
|
|
+ let due = task["due"].as_i64().unwrap();
|
|
|
+ NaiveDateTime::from_timestamp(due, 0).date().format("%A %-d %B").to_string()
|
|
|
+ } else {
|
|
|
+ "".to_string()
|
|
|
+ };
|
|
|
+
|
|
|
+ let rank = task["rank"].as_f64().unwrap_or(0.0) as f32;
|
|
|
+
|
|
|
+ table.add_row(Row::new(vec![
|
|
|
+ Cell::new(&task["id"].to_string()),
|
|
|
+ Cell::new(task["title"].as_str().unwrap()),
|
|
|
+ Cell::new(&projects),
|
|
|
+ Cell::new(&asgn),
|
|
|
+ Cell::new(&date),
|
|
|
+ if rank == max_rank {
|
|
|
+ Cell::new(&rank.to_string()).style_spec("bFC")
|
|
|
+ } else if rank == min_rank {
|
|
|
+ Cell::new(&rank.to_string()).style_spec("Fb")
|
|
|
+ } else {
|
|
|
+ Cell::new(&rank.to_string()).style_spec("Fc")
|
|
|
+ },
|
|
|
+ ]));
|
|
|
+ }
|
|
|
+ table.printstd();
|
|
|
}
|
|
|
}
|
|
|
Ok(())
|