parent
6748cbb183
commit
519162a8db
7 changed files with 34 additions and 6 deletions
|
@ -5,6 +5,9 @@ pub struct Args {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
link: Option<String>,
|
link: Option<String>,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
group: Option<String>,
|
||||||
|
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +15,20 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
let res = repo.insert_task(repo::InsertTaskData {
|
let res = repo.insert_task(repo::InsertTaskData {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
link: args.link,
|
link: args.link,
|
||||||
|
group: args.group,
|
||||||
index: None,
|
index: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
println!("The task was added successfully");
|
println!("The task was added successfully");
|
||||||
|
|
||||||
|
print!(" ");
|
||||||
|
if let Some(group) = task.group {
|
||||||
|
print!("[{}]: ", group);
|
||||||
|
}
|
||||||
println!("{}", task.name);
|
println!("{}", task.name);
|
||||||
|
|
||||||
if let Some(link) = task.link {
|
if let Some(link) = task.link {
|
||||||
println!(" link: {}", link);
|
println!(" link: {}", link);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +37,4 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
eprintln!("Cannot insert a new task: {}", err);
|
eprintln!("Cannot insert a new task: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("added");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@ pub struct Args {
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
group: Option<String>,
|
||||||
|
#[clap(long)]
|
||||||
|
no_group: bool,
|
||||||
|
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +34,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
repo::UpdateTaskData {
|
repo::UpdateTaskData {
|
||||||
name: args.name,
|
name: args.name,
|
||||||
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
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 {
|
match res {
|
||||||
|
|
|
@ -23,9 +23,16 @@ pub fn execute(repo: impl Repository) {
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("{}. ", idx);
|
print!("{}. ", idx);
|
||||||
|
|
||||||
|
if let Some(group) = task.group.as_ref() {
|
||||||
|
print!("[{}]: ", group);
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("{}", task.name);
|
||||||
|
|
||||||
if task.link.is_some() {
|
if task.link.is_some() {
|
||||||
print!(" (link)");
|
print!(" (link)");
|
||||||
}
|
}
|
||||||
println!("{}", task.name);
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
index: Some(new_idx),
|
index: Some(new_idx),
|
||||||
name: target.name,
|
name: target.name,
|
||||||
link: target.link,
|
link: target.link,
|
||||||
|
group: target.group,
|
||||||
});
|
});
|
||||||
match res {
|
match res {
|
||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
|
|
|
@ -3,6 +3,7 @@ pub type TaskId = usize;
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub link: Option<String>,
|
pub link: Option<String>,
|
||||||
|
pub group: Option<String>,
|
||||||
// created_at
|
// created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,14 @@ impl std::error::Error for Error {}
|
||||||
pub struct InsertTaskData {
|
pub struct InsertTaskData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub link: Option<String>,
|
pub link: Option<String>,
|
||||||
|
pub group: Option<String>,
|
||||||
pub index: Option<usize>,
|
pub index: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UpdateTaskData {
|
pub struct UpdateTaskData {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub link: Option<Option<String>>,
|
pub link: Option<Option<String>>,
|
||||||
|
pub group: Option<Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Repository {
|
pub trait Repository {
|
||||||
|
|
|
@ -11,6 +11,7 @@ use xdg::BaseDirectories;
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
name: String,
|
name: String,
|
||||||
link: Option<String>,
|
link: Option<String>,
|
||||||
|
group: Option<String>,
|
||||||
// created_at
|
// created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ impl From<Task> for domain::Task {
|
||||||
domain::Task {
|
domain::Task {
|
||||||
name: repo.name,
|
name: repo.name,
|
||||||
link: repo.link,
|
link: repo.link,
|
||||||
|
group: repo.group,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +117,7 @@ impl Repository for FsRepo {
|
||||||
let new_task = Task {
|
let new_task = Task {
|
||||||
name: insert_data.name,
|
name: insert_data.name,
|
||||||
link: insert_data.link,
|
link: insert_data.link,
|
||||||
|
group: insert_data.group,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tasks = self.get_tasks_impl()?;
|
let mut tasks = self.get_tasks_impl()?;
|
||||||
|
|
Loading…
Reference in a new issue