diff --git a/src/cli.rs b/src/cli.rs index 1d31687..1f4b973 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,6 +14,8 @@ //! along with tas. If not, see . //! +use crate::domain; + pub mod add; pub mod edit; pub mod finish; @@ -43,3 +45,15 @@ pub enum SubCommand { Finish(self::finish::Args), Status, } + +pub fn print_task_detail(task: &domain::Task) { + print!(" "); + if let Some(group) = task.group.as_ref() { + print!("[{}]: ", group); + } + println!("{}", task.name); + + if let Some(link) = task.link.as_ref() { + println!(" link: {}", link); + } +} diff --git a/src/cli/add.rs b/src/cli/add.rs index 420ff76..759f7d0 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -1,4 +1,7 @@ -use crate::repo::{self, Repository}; +use crate::{ + cli::print_task_detail, + repo::{self, Repository}, +}; #[derive(clap::Args)] pub struct Args { @@ -22,16 +25,7 @@ pub fn execute(repo: impl Repository, args: Args) { match res { Ok(task) => { println!("The task was added successfully"); - - print!(" "); - if let Some(group) = task.group { - print!("[{}]: ", group); - } - println!("{}", task.name); - - if let Some(link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); } Err(err) => { eprintln!("Cannot insert a new task: {}", err); diff --git a/src/cli/edit.rs b/src/cli/edit.rs index 2b678ad..5df52fa 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -1,3 +1,4 @@ +use crate::cli::print_task_detail; use crate::repo::{self, Repository}; #[derive(clap::Args)] @@ -40,10 +41,7 @@ pub fn execute(repo: impl Repository, args: Args) { match res { Ok(task) => { println!("The task was changed successfully"); - println!(" {}", task.name); - if let Some(link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); } Err(err) => { eprintln!("Cannot update the task: {}", err); diff --git a/src/cli/finish.rs b/src/cli/finish.rs index f628be2..a0f25f4 100644 --- a/src/cli/finish.rs +++ b/src/cli/finish.rs @@ -1,3 +1,4 @@ +use crate::cli::print_task_detail; use crate::repo::{self, Repository}; #[derive(clap::Args)] @@ -16,10 +17,7 @@ pub fn execute(repo: impl Repository, args: Args) { }; println!("The task was finished successfully"); - println!(" {}", task.name); - if let Some(link) = task.link.as_ref() { - println!(" link: {}", link); - } + print_task_detail(&task); if let (Some(link), true) = (task.link.as_ref(), args.open) { log::debug!("opening link..."); diff --git a/src/cli/list.rs b/src/cli/list.rs index ccec9ad..187c9c2 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -23,13 +23,10 @@ pub fn execute(repo: impl Repository) { } print!("{}. ", idx); - if let Some(group) = task.group.as_ref() { print!("[{}]: ", group); } - print!("{}", task.name); - if task.link.is_some() { print!(" (link)"); } diff --git a/src/cli/pause.rs b/src/cli/pause.rs index 1fc574e..1bb5993 100644 --- a/src/cli/pause.rs +++ b/src/cli/pause.rs @@ -1,3 +1,4 @@ +use crate::cli::print_task_detail; use crate::repo::{self, Repository}; pub fn execute(repo: impl Repository) { @@ -14,10 +15,7 @@ pub fn execute(repo: impl Repository) { match repo.stop_task() { Ok(_) => { println!("The task was paused successfully"); - println!(" {}", task.name); - if let Some(link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); } Err(err) => { eprintln!("Cannot pause the task: {}", err); diff --git a/src/cli/priority.rs b/src/cli/priority.rs index ace1a96..24dbcc2 100644 --- a/src/cli/priority.rs +++ b/src/cli/priority.rs @@ -1,3 +1,4 @@ +use crate::cli::print_task_detail; use crate::repo::{self, Repository}; use std::cmp::Ordering; @@ -64,10 +65,7 @@ pub fn execute(repo: impl Repository, args: Args) { match res { Ok(task) => { println!("The task was reordered successfully"); - println!(" {}", task.name); - if let Some(link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); } Err(err) => { eprintln!("Cannot reorder the task: {}", err); diff --git a/src/cli/remove.rs b/src/cli/remove.rs index 34835fe..35d994d 100644 --- a/src/cli/remove.rs +++ b/src/cli/remove.rs @@ -1,4 +1,7 @@ -use crate::repo::{self, Repository}; +use crate::{ + cli::print_task_detail, + repo::{self, Repository}, +}; use std::io::{BufRead, Write}; #[derive(clap::Args)] @@ -24,10 +27,7 @@ pub fn execute(repo: impl Repository, args: Args) { }; println!("You are deleting task:"); - println!(" {}", task.name); - if let Some(ref link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); println!("In most cases you need to `finish` command"); loop { @@ -46,10 +46,7 @@ pub fn execute(repo: impl Repository, args: Args) { match repo.remove_task(args.idx) { Ok(_) => { println!("The task was removed successfully"); - println!(" {}", task.name); - if let Some(link) = task.link { - println!(" link: {}", link); - } + print_task_detail(&task); } Err(err) => { eprintln!("Cannot remove the task: {}", err); diff --git a/src/cli/start.rs b/src/cli/start.rs index 76aa748..966c14d 100644 --- a/src/cli/start.rs +++ b/src/cli/start.rs @@ -1,4 +1,7 @@ -use crate::repo::{self, Repository}; +use crate::{ + cli::print_task_detail, + repo::{self, Repository}, +}; #[derive(clap::Args)] pub struct Args { @@ -16,10 +19,7 @@ pub fn execute(repo: impl Repository, args: Args) { }; println!("The task was started successfully"); - println!(" {}", task.name); - if let Some(link) = task.link.as_ref() { - println!(" link: {}", link); - } + print_task_detail(&task); if let (Some(link), true) = (task.link.as_ref(), args.open) { log::debug!("opening link..."); diff --git a/src/cli/status.rs b/src/cli/status.rs index 194d639..161acb6 100644 --- a/src/cli/status.rs +++ b/src/cli/status.rs @@ -1,3 +1,4 @@ +use crate::cli::print_task_detail; use crate::repo::Repository; pub fn execute(repo: impl Repository) { @@ -7,10 +8,7 @@ pub fn execute(repo: impl Repository) { } Ok(Some(info)) => { println!("Information about your current task:"); - println!(" {}", info.task.name); - if let Some(link) = info.task.link { - println!(" link: {}", link); - } + print_task_detail(&info.task); } Err(err) => { eprintln!("Cannot read current task: {}", err);