mirror of
https://git.sr.ht/~nixgoat/vento
synced 2025-11-29 16:15:43 +00:00
src: Removed unnecessary contexts
This commit should remove some contexts that actually made some errors more difficult to read. They will now display the idiomatic errors generated by anyhow.
This commit is contained in:
parent
d51163ef09
commit
5e05bfa2ef
10
src/inv.rs
10
src/inv.rs
|
|
@ -34,9 +34,7 @@ pub fn init() -> Result<()> {
|
||||||
let mut answer = String::new();
|
let mut answer = String::new();
|
||||||
print!("⚠️ {} Vento has already been initialized. Reinitializing will delete all files on the directory for Vento. Do you wish to proceed? (y/N) ", "WARNING:".bold().red());
|
print!("⚠️ {} Vento has already been initialized. Reinitializing will delete all files on the directory for Vento. Do you wish to proceed? (y/N) ", "WARNING:".bold().red());
|
||||||
let _ = io::stdout().flush();
|
let _ = io::stdout().flush();
|
||||||
io::stdin()
|
io::stdin().read_line(&mut answer)?;
|
||||||
.read_line(&mut answer)
|
|
||||||
.context("Failed to read input")?;
|
|
||||||
match answer.as_str().trim() {
|
match answer.as_str().trim() {
|
||||||
"y" | "Y" => fs::remove_dir_all(&ventodir)?,
|
"y" | "Y" => fs::remove_dir_all(&ventodir)?,
|
||||||
_ => process::exit(0),
|
_ => process::exit(0),
|
||||||
|
|
@ -190,10 +188,8 @@ fn create_slots() -> Result<()> {
|
||||||
let active = &common::env_config()?.active_dir;
|
let active = &common::env_config()?.active_dir;
|
||||||
let inactive = &common::env_config()?.inactive_dir;
|
let inactive = &common::env_config()?.inactive_dir;
|
||||||
|
|
||||||
let initialize_error = "Vento was unable to initalize. Do you have the correct permissions?";
|
fs::create_dir_all(active)?;
|
||||||
|
fs::create_dir_all(inactive)?;
|
||||||
fs::create_dir_all(active).context(initialize_error)?;
|
|
||||||
fs::create_dir_all(inactive).context(initialize_error)?;
|
|
||||||
|
|
||||||
println!("🎉 {}", "Vento has been succesfully initialized!".green());
|
println!("🎉 {}", "Vento has been succesfully initialized!".green());
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
15
src/item.rs
15
src/item.rs
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use super::common;
|
use super::common;
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Result};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use fs_extra::dir::{move_dir, CopyOptions};
|
use fs_extra::dir::{move_dir, CopyOptions};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
@ -80,11 +80,11 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
|
||||||
|
|
||||||
if sourcepath.is_file() | sourcepath.is_symlink() {
|
if sourcepath.is_file() | sourcepath.is_symlink() {
|
||||||
// Checks the path's file type
|
// Checks the path's file type
|
||||||
fs::copy(&file, &destpath).context("Vento was unable to copy the file.")?;
|
fs::copy(&file, &destpath)?;
|
||||||
fs::remove_file(&file).context("Vento was unable to remove the file.")?;
|
fs::remove_file(&file)?;
|
||||||
} else if sourcepath.is_dir() {
|
} else if sourcepath.is_dir() {
|
||||||
let options = CopyOptions::new();
|
let options = CopyOptions::new();
|
||||||
move_dir(&file, &slotdir, &options).context("Vento was unable to move the directory.")?;
|
move_dir(&file, &slotdir, &options)?;
|
||||||
} else {
|
} else {
|
||||||
bail!("{}", "No such file or directory.".red());
|
bail!("{}", "No such file or directory.".red());
|
||||||
}
|
}
|
||||||
|
|
@ -138,13 +138,12 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
|
||||||
|
|
||||||
if sourcepath.is_file() | sourcepath.is_symlink() {
|
if sourcepath.is_file() | sourcepath.is_symlink() {
|
||||||
// Checks the path's file type
|
// Checks the path's file type
|
||||||
fs::copy(&sourcepath, &destpath).context("Vento was unable to copy the file.")?;
|
fs::copy(&sourcepath, &destpath)?;
|
||||||
fs::remove_file(&sourcepath).context("Vento was unable to remove the file.")?;
|
fs::remove_file(&sourcepath)?;
|
||||||
} else if sourcepath.is_dir() {
|
} else if sourcepath.is_dir() {
|
||||||
let destpath: PathBuf = Path::new(&dest).to_path_buf();
|
let destpath: PathBuf = Path::new(&dest).to_path_buf();
|
||||||
let options = CopyOptions::new();
|
let options = CopyOptions::new();
|
||||||
move_dir(&sourcepath, &destpath, &options)
|
move_dir(&sourcepath, &destpath, &options)?;
|
||||||
.context("Vento was unable to move the directory.")?;
|
|
||||||
} else {
|
} else {
|
||||||
bail!("{}", "No such file or directory.".red());
|
bail!("{}", "No such file or directory.".red());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue