cli/finish: add --open argument

Closes #15
This commit is contained in:
Dmitriy Pleshevskiy 2022-08-16 16:17:26 +03:00
parent ee8d185071
commit 6748cbb183
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 29 additions and 14 deletions

View file

@ -40,6 +40,6 @@ pub enum SubCommand {
List,
Start(self::start::Args),
Pause,
Finish,
Finish(self::finish::Args),
Status,
}

View file

@ -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");
}
}

View file

@ -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);