diff --git a/src/api/mod.rs b/src/api/mod.rs index 5efcd33..83dedb1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -298,6 +298,16 @@ impl VikunjaAPI { serde_json::from_str(&resp).unwrap() } + pub fn fav_task(&self, task_id: isize, fav: bool) -> Task { + let resp = self.post_request( + &format!("/tasks/{task_id}"), + &serde_json::json!({ + "is_favorite": fav + }), + ); + serde_json::from_str(&resp).unwrap() + } + pub fn login(&self, username: &str, password: &str, totp: Option<&str>) -> String { let resp = self.post_request( "/login", diff --git a/src/args.rs b/src/args.rs index 071d7f7..4a2d56b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -68,6 +68,13 @@ pub fn get_args() -> clap::ArgMatches { .arg(arg!([user] "User").required(true)) .arg(arg!([task_id] "Task ID").required(true)), ) + .subcommand( + command!() + .name("fav") + .about("Favorite a task") + .arg(arg!(-u --undo "Remove favorite from task").required(false)) + .arg(arg!([task_id] "Task ID").required(true)), + ) .subcommand( command!() .name("label") diff --git a/src/main.rs b/src/main.rs index fcbeb14..51b5f46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,6 +132,13 @@ fn main() { api.done_task(task_id.parse().unwrap(), done); ui::task::print_task_info(task_id.parse().unwrap(), &api); } + Some(("fav", fav_args)) => { + let task_id: &String = fav_args.get_one("task_id").unwrap(); + let undo = fav_args.get_flag("undo"); + + api.fav_task(task_id.parse().unwrap(), !undo); + ui::task::print_task_info(task_id.parse().unwrap(), &api); + } _ => { let done = arg.get_flag("done"); let fav = arg.get_flag("favorite");