diff --git a/src/cmd.rs b/src/cmd.rs index e6a6ff2..09fad6c 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -52,21 +52,50 @@ pub fn api_call(config_file: &PathBuf, endpoint: String) -> Result { + let projects = parsed.json::().unwrap(); + for project in projects.data { + println!("➡️ ({id}) {name} (uid: {uid})", + id=project.id, + name=project.name, + uid=project.user_id); + } + } + Err(e) => println!("Error happened: {}", e), + } } -pub fn get_tasks(config_file: &PathBuf, project: i32) { - // Config - let mut default_config = config::Config::default(); - let config = default_config.parse(&config_file); - - // Call api - println!("Call API, Config: {:?}", config); - - // Return json result - let tasks = String::from("tasks"); - println!("{}", tasks); - - println!("{}", project); +pub fn get_tasks(config_file: &PathBuf, project: u32) { + let response = api_call(&config_file, String::from("tasks")); + // eprintln!("{:#?}", response); + match response { + Ok(parsed) => { + // println!("{:?}", parsed); + let tasks = parsed.json::().unwrap(); + for task in tasks.data { + match project { + // 0 means no project, print them all + 0 => { + println!("✳️ (pr: {projectid}) ({id}) {name}", + projectid=task.project_id, + id=task.id, + name=task.name); + }, + // Otherwise but 0, print only task with that project.id + _ => { + if project == task.project_id { + println!("✳️ (pr: {projectid}) ({id}) {name}", + projectid=task.project_id, + id=task.id, + name=task.name); + } + } + } + } + } + Err(e) => println!("Error happened: {}", e), + } } diff --git a/src/main.rs b/src/main.rs index 28052dd..2426fa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,9 +27,9 @@ fn main() { } // gst tasks [--project] - ("tasks", Some(matches)) => { + ("tasks", Some(_matches)) => { console::info("List of tasks"); - let project = matches.value_of("project") + let project = _matches.value_of("project") .unwrap_or("0").trim().parse() .expect("Type a number!"); cmd::get_tasks(&config_file, project);