Преглед изворни кода

bin/tau-cli: sort tasks by rank and clean-up

Dastan-glitch пре 4 година
родитељ
комит
bcd5fed5f0
1 измењених фајлова са 7 додато и 6 уклоњено
  1. 7 6
      bin/tau-cli/src/main.rs

+ 7 - 6
bin/tau-cli/src/main.rs

@@ -243,12 +243,12 @@ async fn start(options: CliTau) -> Result<()> {
             };
             };
 
 
             let assign: Vec<String> = match assign {
             let assign: Vec<String> = match assign {
-                Some(a) => a.split(':').map(|s| s.into()).collect(),
+                Some(a) => a.split(',').map(|s| s.into()).collect(),
                 None => vec![],
                 None => vec![],
             };
             };
 
 
             let project: Vec<String> = match project {
             let project: Vec<String> = match project {
-                Some(p) => p.split(':').map(|s| s.into()).collect(),
+                Some(p) => p.split(',').map(|s| s.into()).collect(),
                 None => vec![],
                 None => vec![],
             };
             };
 
 
@@ -259,7 +259,7 @@ async fn start(options: CliTau) -> Result<()> {
 
 
             let rank = rank.unwrap_or(0);
             let rank = rank.unwrap_or(0);
 
 
-            add(rpc_addr, json!([title, desc, project, assign, due, rank])).await?;
+            add(rpc_addr, json!([title, desc, assign, project, due, rank])).await?;
         }
         }
 
 
         Some(CliTauSubCommands::List { month }) => {
         Some(CliTauSubCommands::List { month }) => {
@@ -280,7 +280,9 @@ async fn start(options: CliTau) -> Result<()> {
 
 
             let rep = list(rpc_addr, ts).await?;
             let rep = list(rpc_addr, ts).await?;
 
 
-            let tasks = rep.as_array().unwrap();
+            let mut tasks = rep.as_array().unwrap().to_owned();
+            tasks.sort_by(|a, b| b["rank"].as_u64().cmp(&a["rank"].as_u64()));
+
             for task in tasks {
             for task in tasks {
                 let project = task["project"].as_array().unwrap();
                 let project = task["project"].as_array().unwrap();
                 let mut projects = String::new();
                 let mut projects = String::new();
@@ -307,8 +309,7 @@ async fn start(options: CliTau) -> Result<()> {
                     "".to_string()
                     "".to_string()
                 };
                 };
 
 
-                // TODO: sort lines in table by rank
-                // TODO: the higher the rank the brighter it is
+                // TODO: the highest rank should be brighter
                 table.add_row(row![
                 table.add_row(row![
                     task["id"],
                     task["id"],
                     task["title"].as_str().unwrap(),
                     task["title"].as_str().unwrap(),