Explorar el Código

bin/tau-cli: remove explicit 'list' command in cli

ghassmo hace 4 años
padre
commit
8042cfd946
Se han modificado 1 ficheros con 63 adiciones y 67 borrados
  1. 63 67
      bin/tau/tau-cli/src/main.rs

+ 63 - 67
bin/tau/tau-cli/src/main.rs

@@ -5,7 +5,7 @@ use log::error;
 use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use url::Url;
 
-use darkfi::{cli_desc, rpc::client::RpcClient, util::cli::log_config, Error, Result};
+use darkfi::{rpc::client::RpcClient, util::cli::log_config, Error, Result};
 
 mod filter;
 mod primitives;
@@ -18,8 +18,7 @@ use util::{desc_in_editor, due_as_timestamp};
 use view::{comments_as_string, print_task_info, print_task_list};
 
 #[derive(Parser)]
-#[clap(name = "tau", about = cli_desc!(), version)]
-#[clap(arg_required_else_help(true))]
+#[clap(name = "tau", version)]
 struct Args {
     #[clap(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)
@@ -29,8 +28,11 @@ struct Args {
     /// taud JSON-RPC endpoint
     endpoint: Url,
 
+    /// Search filters (zero or more)
+    filters: Vec<String>,
+
     #[clap(subcommand)]
-    command: TauSubcommand,
+    command: Option<TauSubcommand>,
 }
 
 #[derive(Subcommand)]
@@ -41,7 +43,7 @@ enum TauSubcommand {
     /// Update/Edit an existing task by ID
     Update {
         /// Task ID
-        id: u64,
+        task_id: u64,
         /// Values (ex: project:blockchain)
         values: Vec<String>,
     },
@@ -49,7 +51,7 @@ enum TauSubcommand {
     /// Set or Get task state
     State {
         /// Task ID
-        id: u64,
+        task_id: u64,
         /// Set task state
         state: Option<String>,
     },
@@ -57,19 +59,13 @@ enum TauSubcommand {
     /// Set or Get comment for a task
     Comment {
         /// Task ID
-        id: u64,
+        task_id: u64,
         /// Comment content
         content: Option<String>,
     },
 
-    /// List all tasks
-    List {
-        /// Search criteria (zero or more)
-        filters: Vec<String>,
-    },
-
     /// Get task info by ID
-    Info { id: u64 },
+    Info { task_id: u64 },
 }
 
 pub struct Tau {
@@ -91,70 +87,70 @@ async fn main() -> Result<()> {
 
     // Parse subcommands
     match args.command {
-        TauSubcommand::Add { values } => {
-            let mut task = task_from_cli(values)?;
-            if task.title.is_empty() {
-                error!("Please provide a title for the task.");
-                exit(1);
-            };
-
-            if task.desc.is_none() {
-                task.desc = desc_in_editor()?;
-            };
-
-            return tau.add(task).await
-        }
+        Some(sc) => match sc {
+            TauSubcommand::Add { values } => {
+                let mut task = task_from_cli(values)?;
+                if task.title.is_empty() {
+                    error!("Please provide a title for the task.");
+                    exit(1);
+                };
+
+                if task.desc.is_none() {
+                    task.desc = desc_in_editor()?;
+                };
+
+                return tau.add(task).await
+            }
 
-        TauSubcommand::Update { id, values } => {
-            let task = task_from_cli(values)?;
-            tau.update(id, task).await
-        }
+            TauSubcommand::Update { task_id, values } => {
+                let task = task_from_cli(values)?;
+                tau.update(task_id, task).await
+            }
 
-        TauSubcommand::State { id, state } => match state {
-            Some(state) => {
-                let state = state.trim().to_lowercase();
-                if states.contains(&state.as_str()) {
-                    tau.set_state(id, &state).await
-                } else {
-                    error!(
-                        "Task state can only be one of the following {}: {:?}",
-                        states.len(),
-                        states
-                    );
-                    return Err(Error::OperationFailed)
+            TauSubcommand::State { task_id, state } => match state {
+                Some(state) => {
+                    let state = state.trim().to_lowercase();
+                    if states.contains(&state.as_str()) {
+                        tau.set_state(task_id, &state).await
+                    } else {
+                        error!(
+                            "Task state can only be one of the following {}: {:?}",
+                            states.len(),
+                            states
+                        );
+                        return Err(Error::OperationFailed)
+                    }
                 }
-            }
-            None => {
-                let task = tau.get_task_by_id(id).await?;
-                let state = &task.events.last().unwrap_or(&TaskEvent::default()).action.clone();
-                println!("Task {}: {}", id, state);
-                Ok(())
-            }
-        },
+                None => {
+                    let task = tau.get_task_by_id(task_id).await?;
+                    let state = &task.events.last().unwrap_or(&TaskEvent::default()).action.clone();
+                    println!("Task {}: {}", task_id, state);
+                    Ok(())
+                }
+            },
+
+            TauSubcommand::Comment { task_id, content } => match content {
+                Some(content) => tau.set_comment(task_id, content.trim()).await,
+                None => {
+                    let task = tau.get_task_by_id(task_id).await?;
+                    let comments = comments_as_string(task.comments);
+                    println!("Comments {}:\n{}", task_id, comments);
+                    Ok(())
+                }
+            },
 
-        TauSubcommand::Comment { id, content } => match content {
-            Some(content) => tau.set_comment(id, content.trim()).await,
-            None => {
-                let task = tau.get_task_by_id(id).await?;
-                let comments = comments_as_string(task.comments);
-                println!("Comments {}:\n{}", id, comments);
-                Ok(())
+            TauSubcommand::Info { task_id } => {
+                let task = tau.get_task_by_id(task_id).await?;
+                print_task_info(task)
             }
         },
-
-        TauSubcommand::List { filters } => {
+        None => {
             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, filters)?;
-            Ok(())
-        }
-
-        TauSubcommand::Info { id } => {
-            let task = tau.get_task_by_id(id).await?;
-            print_task_info(task)?;
+            print_task_list(tasks, args.filters)?;
             Ok(())
         }
     }?;