use serde::{Deserialize, Serialize}; use structopt::StructOpt; use structopt_toml::StructOptToml; use darkfi::Result; use super::util::due_as_timestamp; /// Tau cli #[derive(Debug, Deserialize, StructOpt, StructOptToml)] #[serde(default)] #[structopt(name = "tau")] pub struct CliTau { /// Increase verbosity #[structopt(short, parse(from_occurrences))] pub verbose: u8, /// JSON-RPC listen URL #[structopt(long = "rpc", default_value = "tcp://127.0.0.1:11055")] pub rpc_listen: String, /// Sets a custom config file #[structopt(short, long)] pub config: Option, #[structopt(subcommand)] pub command: Option, /// Get task by ID pub id: Option, /// Search criteria (zero or more) #[structopt(multiple = true)] pub filters: Vec, } #[derive(StructOpt, Deserialize, Debug)] pub enum CliTauSubCommands { /// Add a new task Add { values: Vec }, /// Update/Edit an existing task by ID Update { /// Task ID id: u64, /// Values (ex: project:blockchain) values: Vec, }, /// Set or Get task state State { /// Task ID id: u64, /// Set task state state: Option, }, /// Set or Get comment for a task Comment { /// Task ID id: u64, /// Comment content content: Option, }, /// List all tasks List {}, } #[derive(Serialize, Debug, Clone)] pub struct CliBaseTask { pub title: String, pub desc: Option, pub assign: Vec, pub project: Vec, pub due: Option, pub rank: Option, } pub fn task_from_cli_values(values: Vec) -> Result { let mut title: String = String::new(); let mut desc: Option = None; let mut project: Vec = vec![]; let mut assign: Vec = vec![]; let mut due: Option = None; let mut rank: Option = None; for val in values { let field: Vec<&str> = val.split(':').collect(); if field.len() == 1 { title = field[0].into(); continue } if field.len() != 2 { continue } if field[0].starts_with("project") { project = field[1].split(',').map(|s| s.into()).collect(); } if field[0].starts_with("desc") { desc = Some(field[1].into()); } if field[0].starts_with("assign") { assign = field[1].split(',').map(|s| s.into()).collect(); } if field[0].starts_with("due") { due = due_as_timestamp(&field[1]) } if field[0].starts_with("rank") { rank = Some(field[1].parse::()?); } } let task = CliBaseTask { title, desc, project, assign, due, rank }; Ok(task) }