use crate::cli::print_task_detail; use crate::repo::{self, Repository}; #[derive(clap::Args)] pub struct Args { #[clap(short, long)] link: Option, #[clap(long)] no_link: bool, #[clap(short, long)] name: Option, #[clap(short, long)] group: Option, #[clap(long)] no_group: bool, idx: usize, } pub fn execute(repo: impl Repository, args: Args) { match repo.get_current_task_opt() { Ok(Some(_)) => { return eprintln!("You can edit task only when you don't have an active task, yet") } Err(err) => { return eprintln!("Cannot read current task: {}", err); } _ => {} } let res = repo.update_task( args.idx, repo::UpdateTaskData { name: args.name, link: args.no_link.then(|| None).or_else(|| args.link.map(Some)), group: args.no_group.then(|| None).or_else(|| args.group.map(Some)), }, ); match res { Ok(task) => { println!("The task was changed successfully"); print_task_detail(&task); } Err(err) => { eprintln!("Cannot update the task: {}", err); } } }