tas/src/cli/start.rs

53 lines
1.3 KiB
Rust
Raw Normal View History

use crate::{CurrentTaskInfo, Task};
use std::{io::Write, path::PathBuf};
#[derive(clap::Args)]
pub struct Args {
#[clap(short, long)]
open: bool,
idx: Option<usize>,
}
pub struct Request {
2022-08-05 18:25:01 +03:00
pub args: Args,
pub tasks: Vec<Task>,
pub current_task_info: Option<CurrentTaskInfo>,
pub 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");
*/
}