ux improvements

- rename group to project
- rename path to dir_path
- cli/show: add project to the print part
- cli/show: improve print part error message

Closes #25
This commit is contained in:
Dmitriy Pleshevskiy 2022-08-18 14:10:20 +03:00
parent 9837857081
commit 18004c24d0
Signed by: pleshevskiy
GPG Key ID: 1B59187B161C0215
9 changed files with 57 additions and 45 deletions

View File

@ -52,8 +52,8 @@ pub enum SubCommand {
pub fn print_task_detail(task: &domain::Task) {
print!(" ");
if let Some(group) = task.group.as_ref() {
print!("[{}]: ", group);
if let Some(project) = task.project.as_ref() {
print!("[{}]: ", project);
}
println!("{}", task.name);
@ -61,7 +61,7 @@ pub fn print_task_detail(task: &domain::Task) {
println!(" link: {}", link);
}
if let Some(path) = task.path.as_ref() {
println!(" path: {}", path.to_string_lossy());
if let Some(dir_path) = task.dir_path.as_ref() {
println!(" path: {}", dir_path.to_string_lossy());
}
}

View File

@ -21,13 +21,13 @@ use crate::{
#[derive(clap::Args)]
pub struct Args {
#[clap(short, long)]
group: Option<String>,
project: Option<String>,
#[clap(short, long)]
link: Option<String>,
#[clap(short, long)]
path: Option<String>,
#[clap(short, long = "dir")]
dir_path: Option<String>,
name: String,
}
@ -36,8 +36,12 @@ pub fn execute(repo: impl Repository, args: Args) {
let res = repo.insert_task(repo::InsertTaskData {
name: args.name,
link: args.link,
group: args.group,
path: args.path.map(std::fs::canonicalize).transpose().unwrap(),
project: args.project,
dir_path: args
.dir_path
.map(std::fs::canonicalize)
.transpose()
.unwrap(),
index: None,
});

View File

@ -24,19 +24,19 @@ pub struct Args {
name: Option<String>,
#[clap(short, long)]
group: Option<String>,
project: Option<String>,
#[clap(long)]
no_group: bool,
no_project: bool,
#[clap(short, long)]
link: Option<String>,
#[clap(long)]
no_link: bool,
#[clap(short, long)]
path: Option<PathBuf>,
#[clap(long)]
no_path: bool,
#[clap(short, long = "dir")]
dir_path: Option<PathBuf>,
#[clap(long = "no-dir")]
no_dir_path: bool,
idx: usize,
}
@ -46,12 +46,15 @@ pub fn execute(repo: impl Repository, args: Args) {
args.idx,
repo::UpdateTaskData {
name: args.name,
group: args.no_group.then(|| None).or_else(|| args.group.map(Some)),
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
path: args
.no_path
project: args
.no_project
.then(|| None)
.or_else(|| args.path.map(std::fs::canonicalize).transpose().ok()),
.or_else(|| args.project.map(Some)),
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
dir_path: args
.no_dir_path
.then(|| None)
.or_else(|| args.dir_path.map(std::fs::canonicalize).transpose().ok()),
},
);
match res {

View File

@ -18,7 +18,7 @@ use crate::repo::Repository;
#[derive(clap::Args)]
pub struct Args {
groups: Vec<String>,
projects: Vec<String>,
}
pub fn execute(repo: impl Repository, args: Args) {
@ -34,8 +34,8 @@ pub fn execute(repo: impl Repository, args: Args) {
}
};
let groups = args
.groups
let projects = args
.projects
.into_iter()
.map(|g| match g.as_str() {
"-" => None,
@ -46,7 +46,7 @@ pub fn execute(repo: impl Repository, args: Args) {
let filtered_tasks = tasks
.iter()
.enumerate()
.filter(|(_, t)| groups.is_empty() || groups.contains(&t.group));
.filter(|(_, t)| projects.is_empty() || projects.contains(&t.project));
for (i, task) in filtered_tasks {
let idx = i + 1;
@ -57,8 +57,8 @@ pub fn execute(repo: impl Repository, args: Args) {
}
print!("{}. ", idx);
if let Some(group) = task.group.as_ref() {
print!("[{}]: ", group);
if let Some(project) = task.project.as_ref() {
print!("[{}]: ", project);
}
print!("{}", task.name);
if task.link.is_some() {

View File

@ -74,9 +74,9 @@ pub fn execute(repo: impl Repository, args: Args) {
let res = repo.insert_task(repo::InsertTaskData {
index: Some(new_idx),
name: target.name,
group: target.group,
project: target.project,
link: target.link,
path: target.path,
dir_path: target.dir_path,
});
match res {
Ok(task) => {

View File

@ -24,7 +24,8 @@ pub struct Args {
#[derive(clap::ValueEnum, Clone)]
enum PrintPart {
Path,
Project,
DirPath,
Link,
}
@ -33,9 +34,10 @@ impl std::str::FromStr for PrintPart {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"path" => Ok(PrintPart::Path),
"project" => Ok(PrintPart::Project),
"dir" => Ok(PrintPart::DirPath),
"link" => Ok(PrintPart::Link),
_ => Err(r#"You can display only "path" or "link""#),
_ => Err("Available parts: dir, link, project"),
}
}
}
@ -56,10 +58,13 @@ pub fn execute(repo: impl Repository, args: Args) {
println!("Information about your current task:");
print_task_detail(&task);
}
Some(PrintPart::Path) => {
Some(PrintPart::Project) => {
println!("{}", task.project.unwrap_or_else(|| String::from('-')))
}
Some(PrintPart::DirPath) => {
println!(
"{}",
task.path
task.dir_path
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
.to_string_lossy()
)

View File

@ -19,9 +19,9 @@ pub type TaskId = usize;
pub struct Task {
pub name: String,
pub group: Option<String>,
pub project: Option<String>,
pub link: Option<String>,
pub path: Option<PathBuf>,
pub dir_path: Option<PathBuf>,
// created_at
}

View File

@ -40,17 +40,17 @@ impl std::error::Error for Error {}
pub struct InsertTaskData {
pub name: String,
pub group: Option<String>,
pub project: Option<String>,
pub link: Option<String>,
pub path: Option<PathBuf>,
pub dir_path: Option<PathBuf>,
pub index: Option<usize>,
}
pub struct UpdateTaskData {
pub name: Option<String>,
pub group: Option<Option<String>>,
pub project: Option<Option<String>>,
pub link: Option<Option<String>>,
pub path: Option<Option<PathBuf>>,
pub dir_path: Option<Option<PathBuf>>,
}
pub trait Repository {

View File

@ -36,9 +36,9 @@ impl From<Task> for domain::Task {
fn from(repo: Task) -> Self {
domain::Task {
name: repo.name,
group: repo.group,
project: repo.group,
link: repo.link,
path: repo.path.map(PathBuf::from),
dir_path: repo.path.map(PathBuf::from),
}
}
}
@ -120,7 +120,7 @@ impl Repository for FsRepo {
task.name = name;
}
if let Some(group) = update_data.group {
if let Some(group) = update_data.project {
task.group = group;
}
@ -128,7 +128,7 @@ impl Repository for FsRepo {
task.link = link;
}
if let Some(path) = update_data.path {
if let Some(path) = update_data.dir_path {
task.path = path.and_then(|p| p.into_os_string().into_string().ok());
}
@ -142,10 +142,10 @@ impl Repository for FsRepo {
fn insert_task(&self, insert_data: InsertTaskData) -> Result<domain::Task, Error> {
let new_task = Task {
name: insert_data.name,
group: insert_data.group,
group: insert_data.project,
link: insert_data.link,
path: insert_data
.path
.dir_path
.and_then(|p| p.into_os_string().into_string().ok()),
};