extract-cli #9
4 changed files with 84 additions and 50 deletions
|
@ -15,6 +15,8 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
pub mod finish;
|
pub mod finish;
|
||||||
|
pub mod pause;
|
||||||
|
pub mod start;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
|
@ -52,12 +54,7 @@ pub enum SubCommand {
|
||||||
priority: Priority,
|
priority: Priority,
|
||||||
},
|
},
|
||||||
List,
|
List,
|
||||||
Start {
|
Start(self::start::Args),
|
||||||
#[clap(short, long)]
|
|
||||||
open: bool,
|
|
||||||
|
|
||||||
idx: Option<usize>,
|
|
||||||
},
|
|
||||||
Pause,
|
Pause,
|
||||||
Finish,
|
Finish,
|
||||||
Status,
|
Status,
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::CurrentTaskInfo;
|
||||||
|
|
||||||
|
pub struct Request {
|
||||||
|
pub current_task_info: Option<CurrentTaskInfo>,
|
||||||
|
pub current_task_info_file_path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute(mut req: Request) {
|
||||||
|
if req.current_task_info.take().is_none() {
|
||||||
|
panic!("You can use the pause subcommand only when you have an active task");
|
||||||
|
}
|
||||||
|
|
||||||
|
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!("paused");
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
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 {
|
||||||
|
args: Args,
|
||||||
|
tasks: Vec<Task>,
|
||||||
|
current_task_info: Option<CurrentTaskInfo>,
|
||||||
|
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");
|
||||||
|
*/
|
||||||
|
}
|
54
src/main.rs
54
src/main.rs
|
@ -188,50 +188,16 @@ fn main() {
|
||||||
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
cli::SubCommand::Start { idx, open } => {
|
cli::SubCommand::Start(args) => cli::start::execute(cli::start::Request {
|
||||||
let idx = idx.unwrap_or(1);
|
args,
|
||||||
if idx == 0 || idx > tasks.len() {
|
tasks,
|
||||||
panic!("invalid index");
|
current_task_info,
|
||||||
}
|
current_task_info_file_path,
|
||||||
let task = &tasks[idx - 1];
|
}),
|
||||||
|
cli::SubCommand::Pause => cli::pause::execute(cli::pause::Request {
|
||||||
current_task_info.replace(CurrentTaskInfo {
|
current_task_info,
|
||||||
task_idx: idx,
|
current_task_info_file_path,
|
||||||
task: task.clone(),
|
}),
|
||||||
});
|
|
||||||
|
|
||||||
let mut file = std::fs::File::create(¤t_task_info_file_path).unwrap();
|
|
||||||
file.write_all(&serde_json::to_vec(¤t_task_info).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
println!("started");
|
|
||||||
|
|
||||||
if let (Some(link), true) = (task.link.as_ref(), 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");
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
cli::SubCommand::Pause => {
|
|
||||||
if current_task_info.take().is_none() {
|
|
||||||
panic!("You can use the pause subcommand only when you have an active task");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file = std::fs::File::create(¤t_task_info_file_path).unwrap();
|
|
||||||
file.write_all(&serde_json::to_vec(¤t_task_info).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
println!("paused");
|
|
||||||
}
|
|
||||||
cli::SubCommand::Finish => cli::finish::execute(cli::finish::Request {
|
cli::SubCommand::Finish => cli::finish::execute(cli::finish::Request {
|
||||||
tasks,
|
tasks,
|
||||||
current_task_info,
|
current_task_info,
|
||||||
|
|
Loading…
Reference in a new issue