parent
ee8d185071
commit
6748cbb183
3 changed files with 29 additions and 14 deletions
|
@ -40,6 +40,6 @@ pub enum SubCommand {
|
||||||
List,
|
List,
|
||||||
Start(self::start::Args),
|
Start(self::start::Args),
|
||||||
Pause,
|
Pause,
|
||||||
Finish,
|
Finish(self::finish::Args),
|
||||||
Status,
|
Status,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
use crate::repo::{self, Repository};
|
use crate::repo::{self, Repository};
|
||||||
|
|
||||||
pub fn execute(repo: impl Repository) {
|
#[derive(clap::Args)]
|
||||||
match repo.finish_task() {
|
pub struct Args {
|
||||||
Err(repo::Error::NotFound) => {
|
#[clap(short, long)]
|
||||||
eprintln!("You can use the finish subcommand only when you have an active task")
|
open: bool,
|
||||||
}
|
}
|
||||||
Err(err) => eprintln!("Cannot finish the task: {}", err),
|
|
||||||
Ok(task) => {
|
pub fn execute(repo: impl Repository, args: Args) {
|
||||||
|
let task = match repo.finish_task() {
|
||||||
|
Err(repo::Error::NotFound) => {
|
||||||
|
return eprintln!("You can use the finish subcommand only when you have an active task")
|
||||||
|
}
|
||||||
|
Err(err) => return eprintln!("Cannot finish the task: {}", err),
|
||||||
|
Ok(task) => task,
|
||||||
|
};
|
||||||
|
|
||||||
println!("The task was finished successfully");
|
println!("The task was finished successfully");
|
||||||
println!(" {}", task.name);
|
println!(" {}", task.name);
|
||||||
if let Some(link) = task.link {
|
if let Some(link) = task.link.as_ref() {
|
||||||
println!(" link: {}", link);
|
println!(" link: {}", link);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if let (Some(link), true) = (task.link.as_ref(), args.open) {
|
||||||
|
log::debug!("opening link...");
|
||||||
|
std::process::Command::new("xdg-open")
|
||||||
|
.arg(link)
|
||||||
|
.spawn()
|
||||||
|
.expect("failed to start");
|
||||||
|
log::debug!("opened");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ fn main() {
|
||||||
cli::SubCommand::Pause => {
|
cli::SubCommand::Pause => {
|
||||||
cli::pause::execute(repo);
|
cli::pause::execute(repo);
|
||||||
}
|
}
|
||||||
cli::SubCommand::Finish => {
|
cli::SubCommand::Finish(args) => {
|
||||||
cli::finish::execute(repo);
|
cli::finish::execute(repo, args);
|
||||||
}
|
}
|
||||||
cli::SubCommand::Status => {
|
cli::SubCommand::Status => {
|
||||||
cli::status::execute(repo);
|
cli::status::execute(repo);
|
||||||
|
|
Loading…
Reference in a new issue