2022-09-26 19:54:39 +00:00
|
|
|
/*
|
|
|
|
* Vento, a CLI inventory for your files.
|
|
|
|
* Copyright (C) 2022 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-10 00:30:09 +00:00
|
|
|
use anyhow::Result;
|
2023-02-17 05:07:28 +00:00
|
|
|
use std::{env, path::PathBuf};
|
2023-02-10 00:10:39 +00:00
|
|
|
use vento::{
|
2023-02-17 05:07:28 +00:00
|
|
|
archive,
|
2023-08-19 22:42:09 +00:00
|
|
|
message::{throw_error, ErrorType},
|
2023-08-20 00:26:28 +00:00
|
|
|
help, history, inv, common::override_color
|
2023-02-10 00:10:39 +00:00
|
|
|
};
|
2022-09-26 19:54:39 +00:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2022-09-27 23:05:08 +00:00
|
|
|
// Handles args in Vento
|
2023-08-20 00:26:28 +00:00
|
|
|
override_color()?;
|
2022-09-26 19:54:39 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
if args.len() >= 2 {
|
|
|
|
// If the vector for the arguments the command is taking is larger than 2, it most likely means the user has provided an argument
|
|
|
|
if args[1].contains("--slot=") {
|
2022-09-27 23:05:08 +00:00
|
|
|
// Checks if the user has provided the long argument "--slot="
|
2022-09-26 19:54:39 +00:00
|
|
|
match args.len() {
|
|
|
|
3 => inv::list(&args[1].replace("--slot=", ""), &args[2])?,
|
|
|
|
2 => inv::list(&args[1].replace("--slot=", ""), "")?,
|
2023-02-10 00:10:39 +00:00
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
2022-09-26 19:54:39 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
match args[1].as_str() {
|
|
|
|
"-h" | "--help" => help::vento()?,
|
|
|
|
"-i" | "--init" => inv::init()?,
|
2022-11-03 22:42:39 +00:00
|
|
|
"-c" | "--switch" => inv::switch(true)?,
|
2022-11-03 22:26:15 +00:00
|
|
|
"-u" | "--undo" => history::undo()?,
|
2023-02-17 05:07:28 +00:00
|
|
|
"-e" | "--export-inv" => match args.len() {
|
|
|
|
4 => archive::export_inv(&args[2], PathBuf::from(&args[3]), true)?,
|
|
|
|
3 => match args[2].as_str() {
|
|
|
|
"active" | "a" | "inactive" | "i" => {
|
|
|
|
let mut path = PathBuf::from(match args[2].as_str() {
|
|
|
|
"a" => "active",
|
|
|
|
"i" => "inactive",
|
|
|
|
_ => &args[2],
|
|
|
|
});
|
|
|
|
path.set_extension("tar.xz");
|
|
|
|
archive::export_inv(&args[2], path, true)?
|
|
|
|
}
|
|
|
|
_ => archive::export_inv("active", PathBuf::from(&args[2]), true)?,
|
|
|
|
},
|
|
|
|
2 => archive::export_inv("active", PathBuf::from("active.tar.xz"), true)?,
|
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
|
|
|
},
|
2023-02-19 16:15:48 +00:00
|
|
|
"-E" | "--export-dir" => match args.len() {
|
|
|
|
3 => archive::export_dir(PathBuf::from(&args[2]), true)?,
|
|
|
|
2 => archive::export_dir(PathBuf::from("vento.tar.xz"), true)?,
|
2023-02-17 16:37:51 +00:00
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
|
|
|
},
|
2023-02-19 15:49:11 +00:00
|
|
|
"-g" | "--import-inv" => match args.len() {
|
|
|
|
4 => archive::import_inv(PathBuf::from(&args[2]), &args[3], true)?,
|
|
|
|
3 => archive::import_inv(PathBuf::from(&args[2]), "active", true)?,
|
|
|
|
2 => throw_error(ErrorType::SpecifyFile)?,
|
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
|
|
|
},
|
2023-02-19 16:15:48 +00:00
|
|
|
"-G" | "--import-dir" => match args.len() {
|
|
|
|
3 => archive::import_dir(PathBuf::from(&args[2]), true)?,
|
2023-02-19 16:03:36 +00:00
|
|
|
2 => throw_error(ErrorType::SpecifyFile)?,
|
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
|
|
|
},
|
2022-09-26 19:54:39 +00:00
|
|
|
"-s" => match args.len() {
|
|
|
|
4 => inv::list(&args[2], &args[3])?,
|
|
|
|
3 => inv::list(&args[2], "")?,
|
2023-02-10 00:10:39 +00:00
|
|
|
2 => throw_error(ErrorType::SpecifySlot)?,
|
|
|
|
_ => throw_error(ErrorType::TooManyArgs)?,
|
2022-09-26 19:54:39 +00:00
|
|
|
},
|
|
|
|
_ => inv::list("active", args[1].as_str())?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-09-27 23:05:08 +00:00
|
|
|
// If the user provides no arguments, Vento will display the files in the active slot.
|
2022-09-26 19:54:39 +00:00
|
|
|
inv::list("active", "")?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|