Răsfoiți Sursa

bin/tau: minor rework plus log msgs for export and import

Dastan-glitch 4 ani în urmă
părinte
comite
d5c81104a7
2 a modificat fișierele cu 19 adăugiri și 11 ștergeri
  1. 15 7
      bin/tau/tau-cli/src/main.rs
  2. 4 4
      bin/tau/tau-cli/src/rpc.rs

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

@@ -1,7 +1,7 @@
 use std::{process::exit, str::FromStr};
 use std::{process::exit, str::FromStr};
 
 
 use clap::{Parser, Subcommand};
 use clap::{Parser, Subcommand};
-use log::error;
+use log::{error, info};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use url::Url;
 use url::Url;
 
 
@@ -163,19 +163,27 @@ async fn main() -> Result<()> {
             }
             }
 
 
             TauSubcommand::Export { path } => {
             TauSubcommand::Export { path } => {
-                if path.is_some() {
-                    tau.export_to(path.unwrap()).await?;
+                let path = path.unwrap_or(DEFAULT_PATH.into());
+                let res = tau.export_to(path.clone()).await?;
+
+                if res {
+                    info!("Exported to {}", path);
                 } else {
                 } else {
-                    tau.export_to(DEFAULT_PATH.into()).await?;
+                    error!("Error exporting to {}", path);
                 }
                 }
+
                 Ok(())
                 Ok(())
             }
             }
             TauSubcommand::Import { path } => {
             TauSubcommand::Import { path } => {
-                if path.is_some() {
-                    tau.import_from(path.unwrap()).await?;
+                let path = path.unwrap_or(DEFAULT_PATH.into());
+                let res = tau.import_from(path.clone()).await?;
+
+                if res {
+                    info!("Imported from {}", path);
                 } else {
                 } else {
-                    tau.import_from(DEFAULT_PATH.into()).await?;
+                    error!("Error importing from {}", path);
                 }
                 }
+
                 Ok(())
                 Ok(())
             }
             }
         },
         },

+ 4 - 4
bin/tau/tau-cli/src/rpc.rs

@@ -81,22 +81,22 @@ impl Tau {
     }
     }
 
 
     /// Export tasks.
     /// Export tasks.
-    pub async fn export_to(&self, path: String) -> Result<()> {
+    pub async fn export_to(&self, path: String) -> Result<bool> {
         let req = JsonRequest::new("export", json!([path]));
         let req = JsonRequest::new("export", json!([path]));
         let rep = self.rpc_client.request(req).await?;
         let rep = self.rpc_client.request(req).await?;
 
 
         debug!("Got reply: {:?}", rep);
         debug!("Got reply: {:?}", rep);
 
 
-        Ok(())
+        Ok(serde_json::from_value(rep)?)
     }
     }
 
 
     /// Import tasks.
     /// Import tasks.
-    pub async fn import_from(&self, path: String) -> Result<()> {
+    pub async fn import_from(&self, path: String) -> Result<bool> {
         let req = JsonRequest::new("import", json!([path]));
         let req = JsonRequest::new("import", json!([path]));
         let rep = self.rpc_client.request(req).await?;
         let rep = self.rpc_client.request(req).await?;
 
 
         debug!("Got reply: {:?}", rep);
         debug!("Got reply: {:?}", rep);
 
 
-        Ok(())
+        Ok(serde_json::from_value(rep)?)
     }
     }
 }
 }