2022-08-05 21:57:34 +03:00
|
|
|
use std::io::Write;
|
|
|
|
|
2022-08-05 23:40:26 +03:00
|
|
|
use crate::repo::{self, Repository};
|
|
|
|
use crate::CurrentTaskInfo;
|
2022-08-05 21:57:34 +03:00
|
|
|
|
|
|
|
#[derive(clap::Args)]
|
|
|
|
pub struct Args {
|
|
|
|
#[clap(short, long)]
|
|
|
|
link: Option<String>,
|
|
|
|
#[clap(long)]
|
|
|
|
no_link: bool,
|
|
|
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
name: Option<String>,
|
|
|
|
|
|
|
|
idx: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Request {
|
|
|
|
pub args: Args,
|
|
|
|
pub current_task_info: Option<CurrentTaskInfo>,
|
|
|
|
}
|
|
|
|
|
2022-08-05 23:40:26 +03:00
|
|
|
pub fn execute(repo: impl Repository, mut req: Request) {
|
2022-08-05 21:57:34 +03:00
|
|
|
if req.current_task_info.is_some() {
|
|
|
|
panic!("You can edit task only when you don't have an active task, yet");
|
|
|
|
}
|
|
|
|
|
2022-08-05 23:40:26 +03:00
|
|
|
let args = req.args;
|
|
|
|
|
|
|
|
let res = repo.update_task(
|
|
|
|
args.idx,
|
|
|
|
repo::UpdateTaskData {
|
|
|
|
name: args.name,
|
|
|
|
link: args.no_link.then(|| None).or(args.link.map(Some)),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
match res {
|
|
|
|
Ok(task) => {
|
|
|
|
println!("The task was changed successfully");
|
|
|
|
println!(" {}", task.name);
|
|
|
|
if let Some(link) = task.link {
|
|
|
|
println!(" link: {}", link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
eprintln!("Cannot update the task: {}", err);
|
|
|
|
}
|
2022-08-05 21:57:34 +03:00
|
|
|
}
|
|
|
|
}
|