Add colored output to most tools; Make mkoverlay more tolerant for missing overlay files; Make psxcdgen_ex emit a warning when no license file is specified

This commit is contained in:
Jaby Blubb
2023-04-22 15:44:21 +02:00
parent cf19595e47
commit 2f88f0c429
11 changed files with 52 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "tool_helper"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
byteorder = "*"
cdtypes = {path = "../cdtypes"}
colored = "*"
envmnt = "*"
lz4 = "*"
paste = "*"

View File

@@ -1,5 +1,6 @@
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
use colored::*;
use envmnt::{ExpandOptions, ExpansionType};
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
pub mod bits;
pub mod compress;
@@ -79,6 +80,14 @@ impl Error {
pub fn ok_or_new<T, F>(option: Option<T>, error_text: F) -> Result<T, Error> where F: Fn () -> String{
Ok(option.ok_or(Error::from_callback(error_text))?)
}
pub fn print_generic_to_std_err<T: std::fmt::Display>(object: &T) {
eprintln!("{}", format!("ERROR: {}", object).red());
}
pub fn print_to_std_err(&self) {
Self::print_generic_to_std_err(self)
}
}
impl std::fmt::Display for Error {
@@ -105,6 +114,11 @@ impl std::convert::From<std::convert::Infallible> for Error {
}
}
pub fn exit_with_error(error: Error) {
error.print_to_std_err();
std::process::exit(error.exit_code);
}
pub fn prefix_if_error<T>(prefix: &str, result: Result<T, Error>) -> Result<T, Error> {
match result {
Ok(value) => Ok(value),