mirror of https://git.sr.ht/~nixgoat/vento
Compare commits
3 Commits
986c0f7f20
...
791cdf3193
Author | SHA1 | Date |
---|---|---|
Lux Aliaga | 791cdf3193 | |
Lux Aliaga | 4427dadcfc | |
Lux Aliaga | 9e5e0716d1 |
|
@ -17,11 +17,14 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use vento::{help, item};
|
use vento::{
|
||||||
|
common::get_current_dir,
|
||||||
|
error::{throw_error, ErrorType},
|
||||||
|
help, item,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// Handles args in Drop
|
// Handles args in Drop
|
||||||
|
@ -30,34 +33,40 @@ fn main() -> Result<()> {
|
||||||
if args[1].contains("--slot=") {
|
if args[1].contains("--slot=") {
|
||||||
// Checks if the user has provided the long argument "--slot="
|
// Checks if the user has provided the long argument "--slot="
|
||||||
match args.len() {
|
match args.len() {
|
||||||
4 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), Path::new(&args[4]).to_path_buf(), true)?,
|
4 => item::drop(
|
||||||
3 => item::drop(&args[2], &args[1].as_str().replace("--slot=", ""), match env::current_dir() {
|
&args[2],
|
||||||
Ok(dir) => dir,
|
&args[1].as_str().replace("--slot=", ""),
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
Path::new(&args[4]).to_path_buf(),
|
||||||
}, true)?,
|
true,
|
||||||
2 => bail!("{}", "You need to specify a file".red()),
|
)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
3 => item::drop(
|
||||||
|
&args[2],
|
||||||
|
&args[1].as_str().replace("--slot=", ""),
|
||||||
|
get_current_dir()?,
|
||||||
|
true,
|
||||||
|
)?,
|
||||||
|
2 => throw_error(ErrorType::SpecifyFile)?,
|
||||||
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
"--help" | "-h" => help::drop()?,
|
"--help" | "-h" => help::drop()?,
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
5 => item::drop(&args[3], &args[2], Path::new(&args[4]).to_path_buf(), true)?,
|
5 => item::drop(&args[3], &args[2], Path::new(&args[4]).to_path_buf(), true)?,
|
||||||
4 => item::drop(&args[3], &args[2], match env::current_dir() {
|
4 => item::drop(&args[3], &args[2], get_current_dir()?, true)?,
|
||||||
Ok(dir) => dir,
|
3 => throw_error(ErrorType::SpecifyFile)?,
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
2 => throw_error(ErrorType::SpecifySlot)?,
|
||||||
}, true)?,
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
3 => bail!("{}", "You need to specify a file".red()),
|
|
||||||
2 => bail!("{}", "You need to specify a slot".red()),
|
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
|
||||||
},
|
},
|
||||||
_ => match args.len() {
|
_ => match args.len() {
|
||||||
3 => item::drop(&args[1], &String::from("active"), Path::new(&args[2]).to_path_buf(), true)?,
|
3 => item::drop(
|
||||||
2 => item::drop(&args[1], &String::from("active"), match env::current_dir() {
|
&args[1],
|
||||||
Ok(dir) => dir,
|
&String::from("active"),
|
||||||
Err(_) => bail!("{}", "Vento was unable to detect your current directory. Have you configured your environment correctly?".red())
|
Path::new(&args[2]).to_path_buf(),
|
||||||
}, true)?,
|
true,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
)?,
|
||||||
|
2 => item::drop(&args[1], &String::from("active"), get_current_dir()?, true)?,
|
||||||
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use vento::{help, item};
|
use vento::{
|
||||||
|
error::{throw_error, ErrorType},
|
||||||
|
help, item,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// Handles args in Vento
|
// Handles args in Vento
|
||||||
|
@ -30,21 +32,21 @@ fn main() -> Result<()> {
|
||||||
// Checks if the user has provided the long argument "--slot="
|
// Checks if the user has provided the long argument "--slot="
|
||||||
match args.len() {
|
match args.len() {
|
||||||
3 => item::take(&args[2], &args[1].replace("--slot=", ""), true)?,
|
3 => item::take(&args[2], &args[1].replace("--slot=", ""), true)?,
|
||||||
2 => bail!("{}", "You need to specify a file".red()),
|
2 => throw_error(ErrorType::SpecifyFile)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
"--help" | "-h" => help::take()?,
|
"--help" | "-h" => help::take()?,
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
4 => item::take(&args[3], &args[2], true)?,
|
4 => item::take(&args[3], &args[2], true)?,
|
||||||
3 => bail!("{}", "You need to specify a file".red()),
|
3 => throw_error(ErrorType::SpecifyFile)?,
|
||||||
2 => bail!("{}", "You need to specify a slot".red()),
|
2 => throw_error(ErrorType::SpecifySlot)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
},
|
},
|
||||||
_ => match args.len() {
|
_ => match args.len() {
|
||||||
2 => item::take(&args[1], &String::from("active"), true)?,
|
2 => item::take(&args[1], &String::from("active"), true)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use vento::{help, history, inv};
|
use vento::{
|
||||||
|
error::{throw_error, ErrorType},
|
||||||
|
help, history, inv,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// Handles args in Vento
|
// Handles args in Vento
|
||||||
|
@ -32,7 +34,7 @@ fn main() -> Result<()> {
|
||||||
match args.len() {
|
match args.len() {
|
||||||
3 => inv::list(&args[1].replace("--slot=", ""), &args[2])?,
|
3 => inv::list(&args[1].replace("--slot=", ""), &args[2])?,
|
||||||
2 => inv::list(&args[1].replace("--slot=", ""), "")?,
|
2 => inv::list(&args[1].replace("--slot=", ""), "")?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
match args[1].as_str() {
|
match args[1].as_str() {
|
||||||
|
@ -43,8 +45,8 @@ fn main() -> Result<()> {
|
||||||
"-s" => match args.len() {
|
"-s" => match args.len() {
|
||||||
4 => inv::list(&args[2], &args[3])?,
|
4 => inv::list(&args[2], &args[3])?,
|
||||||
3 => inv::list(&args[2], "")?,
|
3 => inv::list(&args[2], "")?,
|
||||||
2 => bail!("{}", "You need to specify a slot".red()),
|
2 => throw_error(ErrorType::SpecifySlot)?,
|
||||||
_ => bail!("{}", "Too many arguments".red()),
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
||||||
},
|
},
|
||||||
_ => inv::list("active", args[1].as_str())?,
|
_ => inv::list("active", args[1].as_str())?,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use crate::error::{throw_error, ErrorType};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
use std::env::current_dir;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -125,3 +127,17 @@ pub fn history(data: HistoryData) -> Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets current directory for commands
|
||||||
|
pub fn get_current_dir() -> Result<PathBuf> {
|
||||||
|
let currentdir = match current_dir() {
|
||||||
|
Ok(dir) => dir,
|
||||||
|
Err(_) => PathBuf::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if currentdir == PathBuf::new() {
|
||||||
|
throw_error(ErrorType::NoCurrentDirectory)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(currentdir)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Vento, a CLI inventory for your files.
|
||||||
|
* Copyright (C) 2023 Lux Aliaga
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
use anyhow::{bail, Result};
|
||||||
|
use colored::Colorize;
|
||||||
|
|
||||||
|
pub enum ErrorType {
|
||||||
|
TooManyArgs,
|
||||||
|
SpecifySlot,
|
||||||
|
SpecifyFile,
|
||||||
|
NoCurrentDirectory,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn throw_error(error: ErrorType) -> Result<()> {
|
||||||
|
bail!(
|
||||||
|
"{}",
|
||||||
|
match error {
|
||||||
|
ErrorType::TooManyArgs => "Too many arguments",
|
||||||
|
ErrorType::SpecifySlot => "You need to specify a file",
|
||||||
|
ErrorType::SpecifyFile => "You need to specify a slot",
|
||||||
|
ErrorType::NoCurrentDirectory => "Vento was unable to detect your current directory. Have you configured your environment correctly?",
|
||||||
|
}
|
||||||
|
.red()
|
||||||
|
);
|
||||||
|
}
|
|
@ -60,51 +60,48 @@ pub fn undo() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"✅ {}",
|
"✅ {}{}{}",
|
||||||
format!(
|
match contents[3] {
|
||||||
"{}{}{}",
|
"take" => "Take",
|
||||||
match contents[3] {
|
"drop" => "Drop",
|
||||||
"take" => "Take",
|
"switch" => "Switch",
|
||||||
"drop" => "Drop",
|
_ => "Unknown",
|
||||||
"switch" => "Switch",
|
}
|
||||||
_ => "Unknown",
|
.bold(),
|
||||||
}
|
" action undone".green(),
|
||||||
.bold(),
|
match contents[3] {
|
||||||
" action undone".green(),
|
"take" => format!(
|
||||||
match contents[3] {
|
"{}{}{}{}{}{}{}",
|
||||||
"take" => format!(
|
" (".green(),
|
||||||
"{}{}{}{}{}{}{}",
|
contents[1].bold(),
|
||||||
" (".green(),
|
", from ".green(),
|
||||||
contents[1].bold(),
|
contents[0],
|
||||||
", from ".green(),
|
" to ".green(),
|
||||||
contents[0],
|
match contents[2] {
|
||||||
" to ".green(),
|
"active" => contents[2].green(),
|
||||||
match contents[2] {
|
"inactive" => contents[2].blue(),
|
||||||
"active" => contents[2].green(),
|
_ => contents[2].red(),
|
||||||
"inactive" => contents[2].blue(),
|
}
|
||||||
_ => contents[2].red(),
|
.bold(),
|
||||||
}
|
" slot)".green(),
|
||||||
.bold(),
|
),
|
||||||
" slot)".green(),
|
"drop" => format!(
|
||||||
),
|
"{}{}{}{}{}{}{}",
|
||||||
"drop" => format!(
|
" (".green(),
|
||||||
"{}{}{}{}{}{}{}",
|
contents[1].bold(),
|
||||||
" (".green(),
|
", from ".green(),
|
||||||
contents[1].bold(),
|
match contents[2] {
|
||||||
", from ".green(),
|
"active" => contents[2].green(),
|
||||||
match contents[2] {
|
"inactive" => contents[2].blue(),
|
||||||
"active" => contents[2].green(),
|
_ => contents[2].red(),
|
||||||
"inactive" => contents[2].blue(),
|
}
|
||||||
_ => contents[2].red(),
|
.bold(),
|
||||||
}
|
" slot to ".green(),
|
||||||
.bold(),
|
contents[0],
|
||||||
" slot to ".green(),
|
")".green(),
|
||||||
contents[0],
|
),
|
||||||
")".green(),
|
_ => String::from(""),
|
||||||
),
|
}
|
||||||
_ => String::from(""),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn init() -> Result<()> {
|
||||||
let _ = io::stdout().flush();
|
let _ = io::stdout().flush();
|
||||||
io::stdin().read_line(&mut answer)?;
|
io::stdin().read_line(&mut answer)?;
|
||||||
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),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -175,9 +175,9 @@ pub fn switch(message: bool) -> Result<()> {
|
||||||
|
|
||||||
let rename_error = "Vento was unable to switch slots. Try running \"vento -i\" and try again";
|
let rename_error = "Vento was unable to switch slots. Try running \"vento -i\" and try again";
|
||||||
|
|
||||||
fs::rename(&active, &temp).context(rename_error)?;
|
fs::rename(active, &temp).context(rename_error)?;
|
||||||
fs::rename(&inactive, &active).context(rename_error)?;
|
fs::rename(inactive, active).context(rename_error)?;
|
||||||
fs::rename(&temp, &inactive).context(rename_error)?;
|
fs::rename(&temp, inactive).context(rename_error)?;
|
||||||
|
|
||||||
common::history(common::HistoryData {
|
common::history(common::HistoryData {
|
||||||
path: PathBuf::new(),
|
path: PathBuf::new(),
|
||||||
|
|
|
@ -72,11 +72,11 @@ pub fn take(file: &String, slot: &str, message: bool) -> 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)?;
|
fs::copy(file, &destpath)?;
|
||||||
fs::remove_file(&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)?;
|
move_dir(file, &slotdir, &options)?;
|
||||||
} else {
|
} else {
|
||||||
bail!("{}", "No such file or directory".red());
|
bail!("{}", "No such file or directory".red());
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<(
|
||||||
} 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)?;
|
||||||
} else {
|
} else {
|
||||||
bail!("{}", "No such file or directory".red());
|
bail!("{}", "No such file or directory".red());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mod common;
|
pub mod common;
|
||||||
|
pub mod error;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
pub mod history;
|
pub mod history;
|
||||||
pub mod inv;
|
pub mod inv;
|
||||||
|
|
Loading…
Reference in New Issue