1
0
Fork 0
mirror of https://git.sr.ht/~nixgoat/vento synced 2025-07-23 13:00:55 +00:00

Compare commits

..

No commits in common. "d0ddc93b4768cda7e32b54473c3154e5f9bf73c3" and "b9cea29592f646ed827bfc233c41290295638aad" have entirely different histories.

4 changed files with 46 additions and 68 deletions

View file

@ -23,11 +23,6 @@ use std::env;
use std::fs::{create_dir_all, File};
use std::io::Write;
struct Page {
content: String,
file: String,
}
fn main() -> Result<()> {
if cfg!(unix) {
let pages = [vento()?, take()?, drop()?, ventotoml()?];
@ -37,16 +32,16 @@ fn main() -> Result<()> {
create_dir_all(tempdir.clone())?;
for page in &pages {
let tempfile = tempdir.join(&page.file);
let tempfile = tempdir.join(page.clone().1);
let mut file = File::create(tempfile).unwrap();
write!(&mut file, "{}", &page.content).unwrap();
write!(&mut file, "{}", page.clone().0).unwrap();
}
}
Ok(())
}
fn vento() -> Result<Page> {
let content = Manual::new("vento")
fn vento() -> Result<(String, String)> {
let page = Manual::new("vento")
.about("a CLI inventory for your files")
.author(Author::new("Lux Aliaga").email("they@mint.lgbt"))
.description("List files and directories in the currently active inventory, the files in SLOT, the files in DIRECTORY or the files in DIRECTORY in SLOT.")
@ -81,14 +76,11 @@ fn vento() -> Result<Page> {
)
.render();
Ok(Page {
content,
file: String::from("vento.1"),
})
Ok((page, String::from("vento.1")))
}
fn take() -> Result<Page> {
let content = Manual::new("take")
fn take() -> Result<(String, String)> {
let page = Manual::new("take")
.about("a file grabber for Vento")
.author(Author::new("Lux Aliaga").email("they@mint.lgbt"))
.description("Take FILE and put it in the inventory.")
@ -101,14 +93,11 @@ fn take() -> Result<Page> {
.arg(Arg::new("FILE"))
.render();
Ok(Page {
content,
file: String::from("take.1"),
})
Ok((page, String::from("take.1")))
}
fn drop() -> Result<Page> {
let content = Manual::new("drop")
fn drop() -> Result<(String, String)> {
let page = Manual::new("drop")
.about("a file dropper for Vento")
.author(Author::new("Lux Aliaga").email("they@mint.lgbt"))
.description("Take FILE off the inventory and drop it in DESTINATION.")
@ -122,14 +111,11 @@ fn drop() -> Result<Page> {
.arg(Arg::new("[DESTINATION]"))
.render();
Ok(Page {
content,
file: String::from("drop.1"),
})
Ok((page, String::from("drop.1")))
}
fn ventotoml() -> Result<Page> {
let content = Manual::new("vento.toml")
fn ventotoml() -> Result<(String, String)> {
let page = Manual::new("vento.toml")
.about("configuration file for Vento")
.author(Author::new("Lux Aliaga").email("they@mint.lgbt"))
.description("This is the configuration file for the vento(1), take(1) and drop(1) utilities. Its presence and all its directives are optional.")
@ -145,8 +131,5 @@ fn ventotoml() -> Result<Page> {
)
.render();
Ok(Page {
content,
file: String::from("vento.toml.1"),
})
Ok((page, String::from("vento.toml.1")))
}

View file

@ -22,13 +22,7 @@ use colored::Colorize;
use config::Config;
use std::path::{Path, PathBuf};
pub struct Settings {
pub vento_dir: PathBuf,
pub active_dir: PathBuf,
pub inactive_dir: PathBuf,
}
pub fn env_config() -> Result<Settings> {
pub fn env_config() -> Result<Vec<PathBuf>> {
// Configures the directories for Vento
let home = match dirs::home_dir() {
Option::Some(dir) => dir,
@ -51,11 +45,7 @@ pub fn env_config() -> Result<Settings> {
.iter()
.collect();
Ok(Settings {
vento_dir,
active_dir,
inactive_dir,
})
Ok(vec![vento_dir, active_dir, inactive_dir])
}
fn dir_config() -> Result<String> {

View file

@ -27,14 +27,16 @@ use std::{fs, process};
pub fn init() -> Result<()> {
// Initializes Vento
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &common::env_config()?[0];
if ventodir.is_dir() {
// Checks if Vento has already been initialized and prompts the user if they want to initialize it again
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());
let _ = io::stdout().flush();
io::stdin().read_line(&mut answer)?;
io::stdin()
.read_line(&mut answer)
.context("Failed to read input")?;
match answer.as_str().trim() {
"y" | "Y" => fs::remove_dir_all(&ventodir)?,
_ => process::exit(0),
@ -47,7 +49,7 @@ pub fn init() -> Result<()> {
pub fn list(slot: &str, dir: &str) -> Result<()> {
// Lists files in inventory
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &common::env_config()?[0];
if !ventodir.is_dir() {
// Detects if Vento hasn't been initialized and bails if so
@ -58,8 +60,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()?[1].clone(),
"inactive" | "i" => common::env_config()?[2].clone(),
_ => PathBuf::new(),
};
@ -166,9 +168,9 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
pub fn switch() -> Result<()> {
// Switches between inventory slots
let ventodir = &common::env_config()?.vento_dir;
let active = &common::env_config()?.active_dir;
let inactive = &common::env_config()?.inactive_dir;
let ventodir = &common::env_config()?[0];
let active = &common::env_config()?[1];
let inactive = &common::env_config()?[2];
let temp: PathBuf = [ventodir.to_path_buf(), Path::new("temp").to_path_buf()]
.iter()
.collect();
@ -185,11 +187,13 @@ pub fn switch() -> Result<()> {
fn create_slots() -> Result<()> {
// Used only on init. Creates all required directories
let active = &common::env_config()?.active_dir;
let inactive = &common::env_config()?.inactive_dir;
let active = &common::env_config()?[1];
let inactive = &common::env_config()?[2];
fs::create_dir_all(active)?;
fs::create_dir_all(inactive)?;
let initialize_error = "Vento was unable to initalize. Do you have the correct permissions?";
fs::create_dir_all(active).context(initialize_error)?;
fs::create_dir_all(inactive).context(initialize_error)?;
println!("🎉 {}", "Vento has been succesfully initialized!".green());
Ok(())

View file

@ -18,7 +18,7 @@
*/
use super::common;
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use colored::Colorize;
use fs_extra::dir::{move_dir, CopyOptions};
use std::fs;
@ -26,7 +26,7 @@ use std::path::{Path, PathBuf};
pub fn take(file: &String, slot: &str) -> Result<()> {
// Takes a file or directory
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &common::env_config()?[0];
if !ventodir.is_dir() {
// Detects if Vento hasn't been initialized and bails if so
@ -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()?[1].clone(),
"inactive" | "i" => common::env_config()?[2].clone(),
_ => PathBuf::new(),
};
@ -80,11 +80,11 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
if sourcepath.is_file() | sourcepath.is_symlink() {
// Checks the path's file type
fs::copy(&file, &destpath)?;
fs::remove_file(&file)?;
fs::copy(&file, &destpath).context("Vento was unable to copy the file.")?;
fs::remove_file(&file).context("Vento was unable to remove the file.")?;
} else if sourcepath.is_dir() {
let options = CopyOptions::new();
move_dir(&file, &slotdir, &options)?;
move_dir(&file, &slotdir, &options).context("Vento was unable to move the directory.")?;
} else {
bail!("{}", "No such file or directory.".red());
}
@ -94,7 +94,7 @@ pub fn take(file: &String, slot: &str) -> Result<()> {
pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
// Drops a file or directory
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &common::env_config()?[0];
if !ventodir.is_dir() {
// Detects if Vento hasn't been initialized and bails if so
@ -105,8 +105,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()?[1].clone(),
"inactive" | "i" => common::env_config()?[2].clone(),
_ => PathBuf::new(),
};
@ -138,12 +138,13 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
if sourcepath.is_file() | sourcepath.is_symlink() {
// Checks the path's file type
fs::copy(&sourcepath, &destpath)?;
fs::remove_file(&sourcepath)?;
fs::copy(&sourcepath, &destpath).context("Vento was unable to copy the file.")?;
fs::remove_file(&sourcepath).context("Vento was unable to remove the file.")?;
} else if sourcepath.is_dir() {
let destpath: PathBuf = Path::new(&dest).to_path_buf();
let options = CopyOptions::new();
move_dir(&sourcepath, &destpath, &options)?;
move_dir(&sourcepath, &destpath, &options)
.context("Vento was unable to move the directory.")?;
} else {
bail!("{}", "No such file or directory.".red());
}