pacwrap/pacwrap/src/main.rs
Xavier Moffett d1622eb0b4
Revised error handling and some cleanup
- `fatal()` function for handling the termination of the program when a
  fatal human-readable error digestable error occurs. This function
  terminates the program and will never return a value.
- Much like the aforementioned function, the `error()` function now
  prints the error and terminates the program, instead of printing the
  error and returning the error code as an i32 integer.
- ErrorType enum implemented as an encapsulate to delineate error type.
- Display trait implemented for ErrorType enum for use cases whereby
  the program being terminated is inconvenient for the given code path.
- `generic()` function added to GenericError trait for handling errors
  of which do not require a message to be prepended.
- Global configuration is now statically cached with OnceLock instead of
  lazy_static, and is loaded on-demand instead of during the invocation
  of the `init()` function from the init module upon program startup.
- Use of lazy_static was also eliminated in pacwrap-core's sync module.
2024-09-19 23:19:26 -04:00

52 lines
2.1 KiB
Rust

/*
* pacwrap
*
* Copyright (C) 2023-2024 Xavier Moffett <sapphirus@azorium.net>
* SPDX-License-Identifier: GPL-3.0-only
*
* 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, version 3.
*
* 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 pacwrap_core::utils::arguments::{Arguments, Operand as Op};
use crate::utils::list;
mod compose;
mod exec;
mod help;
mod proc;
mod query;
mod remove;
mod sync;
mod utils;
fn main() {
let arguments = &mut Arguments::new().populate();
let result = match arguments.next().unwrap_or_default() {
Op::Short('E') | Op::Long("exec") | Op::Value("shell") | Op::Value("run") => exec::execute(arguments),
Op::Short('S') | Op::Long("sync") | Op::Value("sync") | Op::Value("init") => sync::synchronize(arguments),
Op::Short('L') | Op::Long("list") | Op::Value("ls") | Op::Value("list") => list::list_containers(arguments),
Op::Short('R') | Op::Long("remove") | Op::Value("remove") | Op::Value("rm") => remove::remove(arguments),
Op::Short('P') | Op::Long("process") | Op::Value("process") | Op::Value("ps") => proc::process(arguments),
Op::Short('Q') | Op::Long("query") | Op::Value("query") => query::query(arguments),
Op::Short('C') | Op::Long("compose") | Op::Value("compose") => compose::compose(arguments),
Op::Short('U') | Op::Long("utils") | Op::Value("utils") => utils::engage_utility(arguments),
Op::Short('V') | Op::Long("version") | Op::Value("version") => help::print_version(arguments),
Op::Short('h') | Op::Long("help") | Op::Value("help") => help::help(arguments),
_ => arguments.invalid_operand(),
};
if let Err(error) = result {
error.error();
}
}