Parcourir la source

bin/tau: print info after executing each cli command

Dastan-glitch il y a 3 ans
Parent
commit
fe545cc53c
2 fichiers modifiés avec 60 ajouts et 21 suppressions
  1. 44 9
      bin/tau/tau-cli/src/main.rs
  2. 16 12
      bin/tau/tau-cli/src/rpc.rs

+ 44 - 9
bin/tau/tau-cli/src/main.rs

@@ -207,7 +207,11 @@ async fn main() -> Result<()> {
                     exit(1)
                 }
 
-                return tau.add(task).await
+                let title = task.clone().title;
+                if tau.add(task).await? {
+                    println!("Created task \"{}\"", title);
+                }
+                Ok(())
             }
 
             TauSubcommand::Modify { values } => {
@@ -215,9 +219,15 @@ async fn main() -> Result<()> {
                     no_filter_warn()
                 }
                 let base_task = task_from_cli(values)?;
-                for task in tasks {
-                    tau.update(task.id.into(), base_task.clone()).await?;
+                for task in tasks.clone() {
+                    let res = tau.update(task.id.into(), base_task.clone()).await?;
+                    if res {
+                        let tsk = tau.get_task_by_id(task.id.into()).await?;
+                        print_task_info(tsk)?;
+                        println!()
+                    }
                 }
+
                 Ok(())
             }
 
@@ -227,8 +237,11 @@ async fn main() -> Result<()> {
                 }
                 let state = State::Start;
                 for task in tasks {
-                    tau.set_state(task.id.into(), &state).await?;
+                    if tau.set_state(task.id.into(), &state).await? {
+                        println!("Started task: {:?}", task.id);
+                    }
                 }
+
                 Ok(())
             }
 
@@ -238,8 +251,11 @@ async fn main() -> Result<()> {
                 }
                 let state = State::Open;
                 for task in tasks {
-                    tau.set_state(task.id.into(), &state).await?;
+                    if tau.set_state(task.id.into(), &state).await? {
+                        println!("Opened task: {:?}", task.id);
+                    }
                 }
+
                 Ok(())
             }
 
@@ -249,8 +265,11 @@ async fn main() -> Result<()> {
                 }
                 let state = State::Pause;
                 for task in tasks {
-                    tau.set_state(task.id.into(), &state).await?;
+                    if tau.set_state(task.id.into(), &state).await? {
+                        println!("Paused task: {:?}", task.id);
+                    }
                 }
+
                 Ok(())
             }
 
@@ -260,8 +279,11 @@ async fn main() -> Result<()> {
                 }
                 let state = State::Stop;
                 for task in tasks {
-                    tau.set_state(task.id.into(), &state).await?;
+                    if tau.set_state(task.id.into(), &state).await? {
+                        println!("Stopped task: {}", task.id);
+                    }
                 }
+
                 Ok(())
             }
 
@@ -275,7 +297,12 @@ async fn main() -> Result<()> {
                         let comments = comments_as_string(task.comments);
                         println!("Comments {}:\n{}", task.id, comments);
                     } else {
-                        tau.set_comment(task.id.into(), &content.join(" ")).await?;
+                        let res = tau.set_comment(task.id.into(), &content.join(" ")).await?;
+                        if res {
+                            let tsk = tau.get_task_by_id(task.id.into()).await?;
+                            print_task_info(tsk)?;
+                            println!()
+                        }
                     }
                 }
                 Ok(())
@@ -285,10 +312,18 @@ async fn main() -> Result<()> {
                 for task in tasks {
                     let task = tau.get_task_by_id(task.id.into()).await?;
                     print_task_info(task)?;
+                    println!()
                 }
                 Ok(())
             }
-            TauSubcommand::Switch { workspace } => tau.switch_ws(workspace).await,
+
+            TauSubcommand::Switch { workspace } => {
+                if tau.switch_ws(workspace.clone()).await? {
+                    println!("You are now on \"{}\" workspace", workspace);
+                }
+
+                Ok(())
+            }
 
             TauSubcommand::Export { path } => {
                 let path = path.unwrap_or_else(|| DEFAULT_PATH.into());

+ 16 - 12
bin/tau/tau-cli/src/rpc.rs

@@ -17,7 +17,7 @@
  */
 
 use log::debug;
-use serde_json::json;
+use serde_json::{from_value, json};
 
 use darkfi::{rpc::jsonrpc::JsonRequest, Result};
 
@@ -32,12 +32,13 @@ impl Tau {
     }
 
     /// Add a new task.
-    pub async fn add(&self, task: BaseTask) -> Result<()> {
+    pub async fn add(&self, task: BaseTask) -> Result<bool> {
         let req = JsonRequest::new("add", json!([task]));
         let rep = self.rpc_client.request(req).await?;
 
         debug!("Got reply: {:?}", rep);
-        Ok(())
+        let reply: bool = from_value(rep)?;
+        Ok(reply)
     }
 
     /// Get current open tasks ids.
@@ -54,30 +55,33 @@ impl Tau {
     }
 
     /// Update existing task given it's ID and some params.
-    pub async fn update(&self, id: u64, task: BaseTask) -> Result<()> {
+    pub async fn update(&self, id: u64, task: BaseTask) -> Result<bool> {
         let req = JsonRequest::new("update", json!([id, task]));
         let rep = self.rpc_client.request(req).await?;
 
         debug!("Got reply: {:?}", rep);
-        Ok(())
+        let reply: bool = from_value(rep)?;
+        Ok(reply)
     }
 
     /// Set the state for a task.
-    pub async fn set_state(&self, id: u64, state: &State) -> Result<()> {
+    pub async fn set_state(&self, id: u64, state: &State) -> Result<bool> {
         let req = JsonRequest::new("set_state", json!([id, state.to_string()]));
         let rep = self.rpc_client.request(req).await?;
 
         debug!("Got reply: {:?}", rep);
-        Ok(())
+        let reply: bool = from_value(rep)?;
+        Ok(reply)
     }
 
     /// Set a comment for a task.
-    pub async fn set_comment(&self, id: u64, content: &str) -> Result<()> {
+    pub async fn set_comment(&self, id: u64, content: &str) -> Result<bool> {
         let req = JsonRequest::new("set_comment", json!([id, content]));
         let rep = self.rpc_client.request(req).await?;
 
         debug!("Got reply: {:?}", rep);
-        Ok(())
+        let reply: bool = from_value(rep)?;
+        Ok(reply)
     }
 
     /// Get task data by its ID.
@@ -97,13 +101,13 @@ impl Tau {
     }
 
     /// Switch workspace.
-    pub async fn switch_ws(&self, workspace: String) -> Result<()> {
+    pub async fn switch_ws(&self, workspace: String) -> Result<bool> {
         let req = JsonRequest::new("switch_ws", json!([workspace]));
         let rep = self.rpc_client.request(req).await?;
 
         debug!("Got reply: {:?}", rep);
-
-        Ok(())
+        let reply: bool = from_value(rep)?;
+        Ok(reply)
     }
 
     /// Get current workspace.