Bladeren bron

bin/tau: show workspace independently

Dastan-glitch 4 jaren geleden
bovenliggende
commit
77c891e484
5 gewijzigde bestanden met toevoegingen van 25 en 9 verwijderingen
  1. 1 1
      bin/daod/src/main.rs
  2. 2 1
      bin/tau/tau-cli/src/main.rs
  3. 8 0
      bin/tau/tau-cli/src/rpc.rs
  4. 2 7
      bin/tau/tau-cli/src/view.rs
  5. 12 0
      bin/tau/taud/src/jsonrpc.rs

+ 1 - 1
bin/daod/src/main.rs

@@ -18,7 +18,7 @@ mod dao_contract;
 mod demo;
 mod money_contract;
 mod note;
-mod util;
+// mod util;
 use crate::demo::demo;
 
 async fn _start() -> Result<()> {

+ 2 - 1
bin/tau/tau-cli/src/main.rs

@@ -202,12 +202,13 @@ async fn main() -> Result<()> {
             }
         },
         None => {
+            let ws = tau.get_ws().await?;
             let task_ids = tau.get_ids().await?;
             let mut tasks = vec![];
             for id in task_ids {
                 tasks.push(tau.get_task_by_id(id).await?);
             }
-            print_task_list(tasks, args.filters)?;
+            print_task_list(tasks, ws, args.filters)?;
             Ok(())
         }
     }?;

+ 8 - 0
bin/tau/tau-cli/src/rpc.rs

@@ -88,6 +88,14 @@ impl Tau {
         Ok(())
     }
 
+    /// Get current workspace.
+    pub async fn get_ws(&self) -> Result<String> {
+        let req = JsonRequest::new("get_ws", json!([]));
+        let rep = self.rpc_client.request(req).await?;
+
+        Ok(serde_json::from_value(rep)?)
+    }
+
     /// Export tasks.
     pub async fn export_to(&self, path: String) -> Result<bool> {
         let req = JsonRequest::new("export", json!([path]));

+ 2 - 7
bin/tau/tau-cli/src/view.rs

@@ -18,7 +18,7 @@ use crate::{
     TaskEvent,
 };
 
-pub fn print_task_list(tasks: Vec<TaskInfo>, filters: Vec<String>) -> Result<()> {
+pub fn print_task_list(tasks: Vec<TaskInfo>, ws: String, filters: Vec<String>) -> Result<()> {
     let mut tasks = tasks;
 
     let mut table = Table::new();
@@ -47,12 +47,6 @@ pub fn print_task_list(tasks: Vec<TaskInfo>, filters: Vec<String>) -> Result<()>
         min_rank = last.rank;
     }
 
-    let workspace = if tasks.first().is_some() {
-        format!("Workspace: {}", tasks.first().unwrap().workspace.clone())
-    } else {
-        format!("Workspace: ")
-    };
-
     for task in tasks {
         let state = State::from_str(&task.state.clone())?;
 
@@ -83,6 +77,7 @@ pub fn print_task_list(tasks: Vec<TaskInfo>, filters: Vec<String>) -> Result<()>
         ]));
     }
 
+    let workspace = format!("Workspace: {}", ws);
     let mut ws_table = table!([workspace]);
     ws_table.set_format(
         FormatBuilder::new()

+ 12 - 0
bin/tau/taud/src/jsonrpc.rs

@@ -58,6 +58,7 @@ impl RequestHandler for JsonRpcInterface {
             Some("set_comment") => self.set_comment(params).await,
             Some("get_task_by_id") => self.get_task_by_id(params).await,
             Some("switch_ws") => self.switch_ws(params).await,
+            Some("get_ws") => self.get_ws(params).await,
             Some("export") => self.export_to(params).await,
             Some("import") => self.import_from(params).await,
             Some("get_stop_tasks") => self.get_stop_tasks(params).await,
@@ -259,6 +260,17 @@ impl JsonRpcInterface {
         Ok(json!(true))
     }
 
+    // RPCAPI:
+    // Get workspace.
+    // --> {"jsonrpc": "2.0", "method": "get_ws", "params": [], "id": 1}
+    // <-- {"jsonrpc": "2.0", "result": "workspace", "id": 1}
+    async fn get_ws(&self, params: &[Value]) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::switch_ws() params {:?}", params);
+        let ws = self.workspace.lock().await.clone();
+
+        Ok(json!(ws))
+    }
+
     // RPCAPI:
     // Export tasks.
     // --> {"jsonrpc": "2.0", "method": "export_to", "params": [path], "id": 1}