1
0
Fork 0
mirror of https://git.sr.ht/~nixgoat/vento synced 2024-11-21 06:13:16 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Lux Aliaga 5f5ae6e41e
src: Removed redundant clones
These suggestions were made by cargo clippy. These clones were
previously there to remove compiler messages, but it seems like they're
not needed anymore.
2022-10-23 12:54:23 -03:00
Lux Aliaga 839d4dcc76
item: Added take and drop messages
This was suggested by @Ephera@lemmy.ml on Lemmy
(https://slrpnk.net/post/103331/comment/24020) and I've decided to
implement it, since it's not really a hard thing to do and makes the
tool more intuitive.
2022-10-23 11:11:52 -03:00
2 changed files with 28 additions and 21 deletions

View file

@ -58,8 +58,8 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
}
let mut slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?.active_dir.clone(),
"inactive" | "i" => common::env_config()?.inactive_dir.clone(),
"active" | "a" => common::env_config()?.active_dir,
"inactive" | "i" => common::env_config()?.inactive_dir,
_ => PathBuf::new(),
};

View file

@ -36,8 +36,8 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
);
};
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?.active_dir.clone(),
"inactive" | "i" => common::env_config()?.inactive_dir.clone(),
"active" | "a" => common::env_config()?.active_dir,
"inactive" | "i" => common::env_config()?.inactive_dir,
_ => PathBuf::new(),
};
@ -55,20 +55,10 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
};
let sourcepath: PathBuf = Path::new(&file).to_path_buf();
let destpath: PathBuf = [
&slotdir,
&Path::new(
&Path::new(&file)
.file_name()
.unwrap()
.to_os_string()
.to_str()
.unwrap(),
)
.to_path_buf(),
]
.iter()
.collect();
let mut sourcelocation: PathBuf = fs::canonicalize(&sourcepath)?;
sourcelocation.pop();
let filename = Path::new(&file).file_name().unwrap().to_str().unwrap();
let destpath: PathBuf = [&slotdir, &sourcepath].iter().collect();
if Path::exists(&destpath) {
// Checks if there's a file with the same name in the inventory.
@ -89,6 +79,13 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
bail!("{}", "No such file or directory.".red());
}
println!(
"✅ {} {} {} ",
"Took".green(),
&filename.bold(),
format!("from {}", &sourcelocation.to_str().unwrap()).green()
);
Ok(())
}
@ -105,8 +102,8 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
};
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?.active_dir.clone(),
"inactive" | "i" => common::env_config()?.inactive_dir.clone(),
"active" | "a" => common::env_config()?.active_dir,
"inactive" | "i" => common::env_config()?.inactive_dir,
_ => PathBuf::new(),
};
@ -124,7 +121,7 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
};
let sourcepath: PathBuf = [&slotdir, &Path::new(file).to_path_buf()].iter().collect();
let destpath: PathBuf = [
let mut destpath: PathBuf = [
Path::new(&dest).to_path_buf(),
Path::new(file).to_path_buf(),
]
@ -147,5 +144,15 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
} else {
bail!("{}", "No such file or directory.".red());
}
destpath.pop();
println!(
"✅ {} {} {} ",
"Dropped".green(),
&file.bold(),
format!("into {}", &destpath.to_str().unwrap()).green()
);
Ok(())
}