diff --git a/src/cli.rs b/src/cli.rs index 115cba0..7d9f812 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -57,4 +57,8 @@ pub fn print_task_detail(task: &domain::Task) { if let Some(link) = task.link.as_ref() { println!(" link: {}", link); } + + if let Some(path) = task.path.as_ref() { + println!(" path: {}", path.to_string_lossy()); + } } diff --git a/src/cli/add.rs b/src/cli/add.rs index 759f7d0..e8d6624 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -5,11 +5,14 @@ use crate::{ #[derive(clap::Args)] pub struct Args { + #[clap(short, long)] + group: Option, + #[clap(short, long)] link: Option, #[clap(short, long)] - group: Option, + path: Option, name: String, } @@ -19,6 +22,7 @@ pub fn execute(repo: impl Repository, args: Args) { name: args.name, link: args.link, group: args.group, + path: args.path.map(std::fs::canonicalize).transpose().unwrap(), index: None, }); diff --git a/src/cli/edit.rs b/src/cli/edit.rs index 5df52fa..3f0fa28 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -1,13 +1,10 @@ +use std::path::PathBuf; + use crate::cli::print_task_detail; use crate::repo::{self, Repository}; #[derive(clap::Args)] pub struct Args { - #[clap(short, long)] - link: Option, - #[clap(long)] - no_link: bool, - #[clap(short, long)] name: Option, @@ -16,6 +13,16 @@ pub struct Args { #[clap(long)] no_group: bool, + #[clap(short, long)] + link: Option, + #[clap(long)] + no_link: bool, + + #[clap(short, long)] + path: Option, + #[clap(long)] + no_path: bool, + idx: usize, } @@ -34,8 +41,12 @@ pub fn execute(repo: impl Repository, args: Args) { args.idx, 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)), + link: args.no_link.then(|| None).or_else(|| args.link.map(Some)), + path: args + .no_path + .then(|| None) + .or_else(|| args.path.map(std::fs::canonicalize).transpose().ok()), }, ); match res { diff --git a/src/cli/pause.rs b/src/cli/pause.rs index 1bb5993..7f47e09 100644 --- a/src/cli/pause.rs +++ b/src/cli/pause.rs @@ -12,13 +12,6 @@ pub fn execute(repo: impl Repository) { Ok(task) => task, }; - match repo.stop_task() { - Ok(_) => { - println!("The task was paused successfully"); - print_task_detail(&task); - } - Err(err) => { - eprintln!("Cannot pause the task: {}", err); - } - } + println!("The task was paused successfully"); + print_task_detail(&task); } diff --git a/src/cli/priority.rs b/src/cli/priority.rs index 24dbcc2..f2525c1 100644 --- a/src/cli/priority.rs +++ b/src/cli/priority.rs @@ -59,8 +59,9 @@ pub fn execute(repo: impl Repository, args: Args) { let res = repo.insert_task(repo::InsertTaskData { index: Some(new_idx), name: target.name, - link: target.link, group: target.group, + link: target.link, + path: target.path, }); match res { Ok(task) => { diff --git a/src/cli/start.rs b/src/cli/start.rs index 966c14d..7bb6348 100644 --- a/src/cli/start.rs +++ b/src/cli/start.rs @@ -8,6 +8,9 @@ pub struct Args { #[clap(short, long)] open: bool, + #[clap(long)] + print_path: bool, + idx: Option, } @@ -18,8 +21,17 @@ pub fn execute(repo: impl Repository, args: Args) { Err(err) => return eprintln!("Cannot start task: {}", err), }; - println!("The task was started successfully"); - print_task_detail(&task); + if args.print_path { + println!( + "{}", + task.path + .unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir")) + .to_string_lossy() + ) + } else { + println!("The task was started successfully"); + print_task_detail(&task); + } if let (Some(link), true) = (task.link.as_ref(), args.open) { log::debug!("opening link..."); diff --git a/src/domain.rs b/src/domain.rs index bb9915d..e214d61 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1,9 +1,12 @@ +use std::path::PathBuf; + pub type TaskId = usize; pub struct Task { pub name: String, - pub link: Option, pub group: Option, + pub link: Option, + pub path: Option, // created_at } diff --git a/src/repo.rs b/src/repo.rs index d8c60fa..0eae031 100755 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,5 +1,7 @@ pub mod fs; +use std::path::PathBuf; + use crate::domain; #[derive(Debug)] @@ -23,15 +25,17 @@ impl std::error::Error for Error {} pub struct InsertTaskData { pub name: String, - pub link: Option, pub group: Option, + pub link: Option, + pub path: Option, pub index: Option, } pub struct UpdateTaskData { pub name: Option, - pub link: Option>, pub group: Option>, + pub link: Option>, + pub path: Option>, } pub trait Repository { diff --git a/src/repo/fs.rs b/src/repo/fs.rs index 3261316..6e68cfa 100644 --- a/src/repo/fs.rs +++ b/src/repo/fs.rs @@ -1,5 +1,6 @@ use std::fs::File; use std::io::Write; +use std::path::PathBuf; use crate::domain; use crate::repo::{Error, InsertTaskData, Repository, UpdateTaskData}; @@ -10,8 +11,9 @@ use xdg::BaseDirectories; #[derive(Deserialize, Serialize, Clone)] pub struct Task { name: String, - link: Option, group: Option, + link: Option, + path: Option, // created_at } @@ -19,8 +21,9 @@ impl From for domain::Task { fn from(repo: Task) -> Self { domain::Task { name: repo.name, - link: repo.link, group: repo.group, + link: repo.link, + path: repo.path.map(PathBuf::from), } } } @@ -102,12 +105,16 @@ impl Repository for FsRepo { task.name = name; } + if let Some(group) = update_data.group { + task.group = group; + } + if let Some(link) = update_data.link { task.link = link; } - if let Some(group) = update_data.group { - task.group = group; + if let Some(path) = update_data.path { + task.path = path.and_then(|p| p.into_os_string().into_string().ok()); } let new_task = task.clone(); @@ -120,8 +127,11 @@ impl Repository for FsRepo { fn insert_task(&self, insert_data: InsertTaskData) -> Result { let new_task = Task { name: insert_data.name, - link: insert_data.link, group: insert_data.group, + link: insert_data.link, + path: insert_data + .path + .and_then(|p| p.into_os_string().into_string().ok()), }; let mut tasks = self.get_tasks_impl()?;