use crate::{CurrentTaskInfo, Task}; use std::{io::Write, path::PathBuf}; #[derive(clap::Args)] pub struct Args { #[clap(short, long)] open: bool, idx: Option, } pub struct Request { args: Args, tasks: Vec, current_task_info: Option, current_task_info_file_path: PathBuf, } pub fn execute(mut req: Request) { let idx = req.args.idx.unwrap_or(1); if idx == 0 || idx > req.tasks.len() { panic!("invalid index"); } let task = &req.tasks[idx - 1]; req.current_task_info.replace(CurrentTaskInfo { task_idx: idx, task: task.clone(), }); let mut file = std::fs::File::create(&req.current_task_info_file_path).unwrap(); file.write_all(&serde_json::to_vec(&req.current_task_info).unwrap()) .unwrap(); println!("started"); if let (Some(link), true) = (task.link.as_ref(), req.args.open) { log::debug!("opening link..."); std::process::Command::new("xdg-open") .arg(link) .spawn() .expect("failed to start"); log::debug!("opened"); } /* println!("starting..."); println!("-- on start hook found"); println!("-- running..."); println!("> curl ..."); println!("-- status was changed to \"In progress\" successfuly"); */ }