From effdbb778a87674fdc1fcc9e070f367b7c740be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Wed, 17 Nov 2021 19:30:43 +0100 Subject: [PATCH] Add: New "addtask" command --- src/cli.rs | 28 ++++++++++++++++++++++++++++ src/main.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 473ee88..dd4c7fb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -41,4 +41,32 @@ pub fn build_cli() -> App<'static, 'static> { .takes_value(true), ), ) + .subcommand( + SubCommand::with_name("addtask") + .about("Add a new task to a project") + .arg( + Arg::with_name("project") + .short("p") + .long("project") + .value_name("PROJECT") + .help("Provides a project to list tasks from") + .takes_value(true), + ) + .arg( + Arg::with_name("title") + .short("t") + .long("title") + .value_name("TITLE") + .help("Task title") + .takes_value(true), + ) + .arg( + Arg::with_name("description") + .short("d") + .long("description") + .value_name("DESCRIPTION") + .help("Task description") + .takes_value(true), + ) + ) } diff --git a/src/main.rs b/src/main.rs index a5c6091..3b6a5f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use std::{process}; use std::path::PathBuf; mod cli; -mod cmd; pub mod console; #[path = "./models/tasks.rs"] @@ -66,6 +65,32 @@ fn main() { stamps.get(&config_file, last); } + // gst addtask [--project] "title" + ("addtask", Some(_matches)) => { + console::info("Add a new task"); + let project: u32 = _matches.value_of("project") + .unwrap_or("0").trim().parse() + .expect("Type a number!"); + let title: &str = _matches.value_of("title") + .unwrap_or("").trim(); + let description: &str = _matches.value_of("description") + .unwrap_or("").trim(); + let task = Task { + id: 0, + name: title.to_string(), + description: Some(description.to_string()), + project_id: project, + estimated: Some("1:00:00".to_string()), + }; + // println!("{:?}", task); + let added = task.add(&config_file); + // println!("{:#?}", added); + match added.status() { + reqwest::StatusCode::OK => println!("OK"), + other => println!("KO: {:?}, something happened", other), + } + } + _ => console::error("Whut!!!"), } }