From 519162a8db88ac8a9a50bd39d3ce9392601d31f6 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 16 Aug 2022 16:36:53 +0300 Subject: [PATCH] add optional group to the task Closes #17 --- src/cli/add.rs | 14 +++++++++++--- src/cli/edit.rs | 6 ++++++ src/cli/list.rs | 13 ++++++++++--- src/cli/priority.rs | 1 + src/domain.rs | 1 + src/repo.rs | 2 ++ src/repo/fs.rs | 3 +++ 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/cli/add.rs b/src/cli/add.rs index b928042..420ff76 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -5,6 +5,9 @@ pub struct Args { #[clap(short, long)] link: Option, + #[clap(short, long)] + group: Option, + name: String, } @@ -12,13 +15,20 @@ pub fn execute(repo: impl Repository, args: Args) { let res = repo.insert_task(repo::InsertTaskData { name: args.name, link: args.link, + group: args.group, index: None, }); match res { Ok(task) => { println!("The task was added successfully"); - println!(" {}", task.name); + + print!(" "); + if let Some(group) = task.group { + print!("[{}]: ", group); + } + println!("{}", task.name); + if let Some(link) = task.link { println!(" link: {}", link); } @@ -27,6 +37,4 @@ pub fn execute(repo: impl Repository, args: Args) { eprintln!("Cannot insert a new task: {}", err); } } - - println!("added"); } diff --git a/src/cli/edit.rs b/src/cli/edit.rs index aa101bf..2b678ad 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -10,6 +10,11 @@ pub struct Args { #[clap(short, long)] name: Option, + #[clap(short, long)] + group: Option, + #[clap(long)] + no_group: bool, + idx: usize, } @@ -29,6 +34,7 @@ pub fn execute(repo: impl Repository, args: Args) { repo::UpdateTaskData { name: args.name, link: args.no_link.then(|| None).or_else(|| args.link.map(Some)), + group: args.no_group.then(|| None).or_else(|| args.group.map(Some)), }, ); match res { diff --git a/src/cli/list.rs b/src/cli/list.rs index d309534..ccec9ad 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -23,9 +23,16 @@ pub fn execute(repo: impl Repository) { } print!("{}. ", idx); - if task.link.is_some() { - print!("(link) "); + + if let Some(group) = task.group.as_ref() { + print!("[{}]: ", group); } - println!("{}", task.name); + + print!("{}", task.name); + + if task.link.is_some() { + print!(" (link)"); + } + println!(); } } diff --git a/src/cli/priority.rs b/src/cli/priority.rs index bc8a5dc..ace1a96 100644 --- a/src/cli/priority.rs +++ b/src/cli/priority.rs @@ -59,6 +59,7 @@ pub fn execute(repo: impl Repository, args: Args) { index: Some(new_idx), name: target.name, link: target.link, + group: target.group, }); match res { Ok(task) => { diff --git a/src/domain.rs b/src/domain.rs index f52d9f0..bb9915d 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -3,6 +3,7 @@ pub type TaskId = usize; pub struct Task { pub name: String, pub link: Option, + pub group: Option, // created_at } diff --git a/src/repo.rs b/src/repo.rs index 00097c3..d8c60fa 100755 --- a/src/repo.rs +++ b/src/repo.rs @@ -24,12 +24,14 @@ impl std::error::Error for Error {} pub struct InsertTaskData { pub name: String, pub link: Option, + pub group: Option, pub index: Option, } pub struct UpdateTaskData { pub name: Option, pub link: Option>, + pub group: Option>, } pub trait Repository { diff --git a/src/repo/fs.rs b/src/repo/fs.rs index 01e0678..6b8ed3e 100644 --- a/src/repo/fs.rs +++ b/src/repo/fs.rs @@ -11,6 +11,7 @@ use xdg::BaseDirectories; pub struct Task { name: String, link: Option, + group: Option, // created_at } @@ -19,6 +20,7 @@ impl From for domain::Task { domain::Task { name: repo.name, link: repo.link, + group: repo.group, } } } @@ -115,6 +117,7 @@ impl Repository for FsRepo { let new_task = Task { name: insert_data.name, link: insert_data.link, + group: insert_data.group, }; let mut tasks = self.get_tasks_impl()?;