From 4e8c3114762cc56a745b5f0b32f2603e128e003b Mon Sep 17 00:00:00 2001 From: scbj Date: Wed, 9 Jul 2025 10:39:33 +0200 Subject: [PATCH] improved output of `book remove` & added todo --- README.md | 5 +++-- src/bookmarks.rs | 10 +++++++--- src/main.rs | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 450efd2..f8e3a13 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,9 @@ The following formats are supported: - [x] do not resolve links in bookmarks - [x] option to show invalid paths - [x] style option for invalid paths - - [x] subcommand to remove invalid paths - - [ ] print deleted bookmarks + - [x] subcommand to remove invalid paths + - [ ] print deleted bookmarks + - [ ] consistent output of `remove` subcommand - [x] push to push path in stack - [x] write documentation - [x] change config file extension to `.toml` diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 74df318..fc80a82 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -89,16 +89,20 @@ impl Bookmarks { } /// removes a the entry with key=name if it exists, then writes the bookmarks file - pub fn remove_bookmark(&mut self, name: &String) -> Result<()> { + pub fn remove_bookmark(&mut self, name: &String) -> Result { + let path: PathBuf; if self.bookmarks.contains_key(name) { - _ = self.bookmarks.remove(name); + path = match self.bookmarks.remove(name) { + Some(path) => path, + None => return Err(Error::other("-- those bastards, they lied to me!")), + }; self.write_bookmark_file()?; } else { return Err(Error::other( "-- bookmark requested to delete does not exist", )); } - Ok(()) + Ok(path) } /// diff --git a/src/main.rs b/src/main.rs index 3da7acc..f4fc6e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,12 +214,12 @@ fn add_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookma } fn remove_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookmarks, output: &mut Output) -> Result<()> { - bookmarks.remove_bookmark(&args.name)?; + let path = bookmarks.remove_bookmark(&args.name)?; if config.general.show_entries_on_bookmark { output.push_info(&bookmarks.to_formatted_string(config)?); } else { - output.push_info(&format!("remove bookmark `{}{}{}`.", generate_style_sequence(Some(STYLES.set.bold), None, None), args.name, RESET_SEQ)); + output.push_info(&format!("removed bookmark `{}{}{}{}{}`.", generate_style_sequence(Some(STYLES.set.bold), None, None), args.name, config.format.bookmarks_separator, path.to_str().unwrap(), RESET_SEQ)); } Ok(()) }