diff --git a/src/cli.rs b/src/cli.rs index 8e2fa53..51f2d42 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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()); } } diff --git a/src/cli/add.rs b/src/cli/add.rs index a210a5b..bd3373b 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -21,13 +21,13 @@ use crate::{ #[derive(clap::Args)] pub struct Args { #[clap(short, long)] - group: Option, + project: Option, #[clap(short, long)] link: Option, - #[clap(short, long)] - path: Option, + #[clap(short, long = "dir")] + dir_path: Option, 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, }); diff --git a/src/cli/edit.rs b/src/cli/edit.rs index dd4115b..99baeac 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -24,19 +24,19 @@ pub struct Args { name: Option, #[clap(short, long)] - group: Option, + project: Option, #[clap(long)] - no_group: bool, + no_project: bool, #[clap(short, long)] link: Option, #[clap(long)] no_link: bool, - #[clap(short, long)] - path: Option, - #[clap(long)] - no_path: bool, + #[clap(short, long = "dir")] + dir_path: Option, + #[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 { diff --git a/src/cli/list.rs b/src/cli/list.rs index 1f5128c..9703bfc 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -18,7 +18,7 @@ use crate::repo::Repository; #[derive(clap::Args)] pub struct Args { - groups: Vec, + projects: Vec, } 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() { diff --git a/src/cli/priority.rs b/src/cli/priority.rs index dd2c4a0..5b360a8 100644 --- a/src/cli/priority.rs +++ b/src/cli/priority.rs @@ -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) => { diff --git a/src/cli/show.rs b/src/cli/show.rs index 2e367af..a237c99 100644 --- a/src/cli/show.rs +++ b/src/cli/show.rs @@ -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 { 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() ) diff --git a/src/domain.rs b/src/domain.rs index 4c7bfd7..45ca64b 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -19,9 +19,9 @@ pub type TaskId = usize; pub struct Task { pub name: String, - pub group: Option, + pub project: Option, pub link: Option, - pub path: Option, + pub dir_path: Option, // created_at } diff --git a/src/repo.rs b/src/repo.rs index 081496f..6c6ca09 100755 --- a/src/repo.rs +++ b/src/repo.rs @@ -40,17 +40,17 @@ impl std::error::Error for Error {} pub struct InsertTaskData { pub name: String, - pub group: Option, + pub project: Option, pub link: Option, - pub path: Option, + pub dir_path: Option, pub index: Option, } pub struct UpdateTaskData { pub name: Option, - pub group: Option>, + pub project: Option>, pub link: Option>, - pub path: Option>, + pub dir_path: Option>, } pub trait Repository { diff --git a/src/repo/fs.rs b/src/repo/fs.rs index 5e0bfa2..86811ef 100644 --- a/src/repo/fs.rs +++ b/src/repo/fs.rs @@ -36,9 +36,9 @@ impl From 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 { 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()), };