2022-08-16 16:44:04 +03:00
|
|
|
use crate::{
|
|
|
|
cli::print_task_detail,
|
|
|
|
repo::{self, Repository},
|
|
|
|
};
|
2022-08-05 17:58:54 +03:00
|
|
|
|
|
|
|
#[derive(clap::Args)]
|
|
|
|
pub struct Args {
|
|
|
|
#[clap(short, long)]
|
|
|
|
open: bool,
|
|
|
|
|
2022-08-16 22:24:21 +03:00
|
|
|
#[clap(long)]
|
|
|
|
print_path: bool,
|
|
|
|
|
2022-08-05 17:58:54 +03:00
|
|
|
idx: Option<usize>,
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:43:44 +03:00
|
|
|
pub fn execute(repo: impl Repository, args: Args) {
|
|
|
|
let task = match repo.start_task(args.idx.unwrap_or(1)) {
|
|
|
|
Ok(task) => task,
|
|
|
|
Err(repo::Error::NotFound) => return eprintln!("Task not found"),
|
|
|
|
Err(err) => return eprintln!("Cannot start task: {}", err),
|
|
|
|
};
|
|
|
|
|
2022-08-16 22:24:21 +03:00
|
|
|
if args.print_path {
|
|
|
|
println!(
|
|
|
|
"{}",
|
|
|
|
task.path
|
|
|
|
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
|
|
|
|
.to_string_lossy()
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
println!("The task was started successfully");
|
|
|
|
print_task_detail(&task);
|
|
|
|
}
|
2022-08-05 17:58:54 +03:00
|
|
|
|
2022-08-16 15:43:44 +03:00
|
|
|
if let (Some(link), true) = (task.link.as_ref(), args.open) {
|
2022-08-05 17:58:54 +03:00
|
|
|
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");
|
|
|
|
*/
|
|
|
|
}
|