add optional group to the task

Closes #17
This commit is contained in:
Dmitriy Pleshevskiy 2022-08-16 16:36:53 +03:00
parent 6748cbb183
commit 519162a8db
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
7 changed files with 34 additions and 6 deletions

View File

@ -5,6 +5,9 @@ pub struct Args {
#[clap(short, long)]
link: Option<String>,
#[clap(short, long)]
group: Option<String>,
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");
}

View File

@ -10,6 +10,11 @@ pub struct Args {
#[clap(short, long)]
name: Option<String>,
#[clap(short, long)]
group: Option<String>,
#[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 {

View File

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

View File

@ -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) => {

View File

@ -3,6 +3,7 @@ pub type TaskId = usize;
pub struct Task {
pub name: String,
pub link: Option<String>,
pub group: Option<String>,
// created_at
}

View File

@ -24,12 +24,14 @@ impl std::error::Error for Error {}
pub struct InsertTaskData {
pub name: String,
pub link: Option<String>,
pub group: Option<String>,
pub index: Option<usize>,
}
pub struct UpdateTaskData {
pub name: Option<String>,
pub link: Option<Option<String>>,
pub group: Option<Option<String>>,
}
pub trait Repository {

View File

@ -11,6 +11,7 @@ use xdg::BaseDirectories;
pub struct Task {
name: String,
link: Option<String>,
group: Option<String>,
// created_at
}
@ -19,6 +20,7 @@ impl From<Task> 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()?;