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