added check to not overwrite existing bookmarks
This commit is contained in:
+4
-1
@@ -9,7 +9,7 @@ use std::str::FromStr;
|
|||||||
use dirs::{config_dir, home_dir};
|
use dirs::{config_dir, home_dir};
|
||||||
|
|
||||||
use super::{config::*, util::to_rooted};
|
use super::{config::*, util::to_rooted};
|
||||||
use config_parser::{apply_format, make_padding_string, RESET_SEQ};
|
use config_parser::{apply_format, generate_style_sequence, make_padding_string, RESET_SEQ, STYLES};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Bookmarks {
|
pub struct Bookmarks {
|
||||||
@@ -72,6 +72,9 @@ impl Bookmarks {
|
|||||||
pub fn add_bookmark(&mut self, name: &String, path: &PathBuf) -> Result<()> {
|
pub fn add_bookmark(&mut self, name: &String, path: &PathBuf) -> Result<()> {
|
||||||
let mut path = path.to_path_buf();
|
let mut path = path.to_path_buf();
|
||||||
to_rooted(&mut path)?;
|
to_rooted(&mut path)?;
|
||||||
|
if self.bookmarks.contains_key(name) {
|
||||||
|
return Err(Error::other(format!("-- bookmark with name `{name}` already exists")));
|
||||||
|
}
|
||||||
if !path.is_dir() {
|
if !path.is_dir() {
|
||||||
return Err(Error::other(
|
return Err(Error::other(
|
||||||
"-- provided path argument does not point to a valid directory",
|
"-- provided path argument does not point to a valid directory",
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
pub fn debug_print(string: &str) {
|
|
||||||
println!("echo '{}' && ", string);
|
|
||||||
}
|
|
||||||
+6
-4
@@ -4,7 +4,6 @@ mod bookmarks;
|
|||||||
mod stack;
|
mod stack;
|
||||||
mod output;
|
mod output;
|
||||||
mod util;
|
mod util;
|
||||||
mod debug;
|
|
||||||
|
|
||||||
use arguments::*;
|
use arguments::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@@ -192,7 +191,7 @@ fn list_bookmarks(config: &Config, bookmarks: &mut Bookmarks, output: &mut Outpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookmarks, output: &mut Output) -> Result<()> {
|
fn add_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookmarks, output: &mut Output) -> Result<()> {
|
||||||
let path = match args.path.clone() {
|
let mut path = match args.path.clone() {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => return Err(Error::other("-- missing path argument")),
|
None => return Err(Error::other("-- missing path argument")),
|
||||||
};
|
};
|
||||||
@@ -201,7 +200,10 @@ fn add_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Bookma
|
|||||||
if config.general.show_books_on_bookmark {
|
if config.general.show_books_on_bookmark {
|
||||||
output.push_info(&bookmarks.to_formatted_string(config)?);
|
output.push_info(&bookmarks.to_formatted_string(config)?);
|
||||||
} else {
|
} else {
|
||||||
output.push_info(&format!("added bookmark `{}{}{}`.", generate_style_sequence(Some(STYLES.set.bold), None, None), args.name, RESET_SEQ));
|
_ = to_rooted(&mut path);
|
||||||
|
output.push_info(&format!("added bookmark `{}{}{} = {}{}{}`.",
|
||||||
|
generate_style_sequence(Some(STYLES.set.bold), None, None), args.name, RESET_SEQ,
|
||||||
|
generate_style_sequence(Some(STYLES.set.italic), None, None), path.to_str().unwrap(), RESET_SEQ));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -219,7 +221,7 @@ fn remove_bookmarks(args: &BookmarkSubArgs, config: &Config, bookmarks: &mut Boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// push path to stack and print command to navigate to provided path
|
/// push path to stack and print command to navigate to provided path
|
||||||
fn push_path(path: &Path, stack: &mut Stack, config: &Config, output: &mut Output) -> Result<()> {
|
fn push_path(path: &Path, stack: &mut Stack, _config: &Config, output: &mut Output) -> Result<()> {
|
||||||
let mut path = path.to_path_buf();
|
let mut path = path.to_path_buf();
|
||||||
let mut current_path: PathBuf = current_dir()?;
|
let mut current_path: PathBuf = current_dir()?;
|
||||||
to_rooted(&mut path)?;
|
to_rooted(&mut path)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user