Add: New "addtask" command

This commit is contained in:
Óscar M. Lage 2021-11-17 19:30:43 +01:00
parent aba7a2bc03
commit effdbb778a
2 changed files with 54 additions and 1 deletions

View File

@ -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),
)
)
}

View File

@ -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!!!"),
}
}