Skip to content

Commit

Permalink
fix: Use same parameters for release and debug macros
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Mar 21, 2024
1 parent c16d0a9 commit 7a200b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "re_set-lib"
version = "2.9.0"
version = "2.9.1"
edition = "2021"
description = "Data structure library for ReSet"
repository = "https://github.com/Xetibo/ReSet-Lib"
Expand Down
37 changes: 6 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,61 +68,37 @@ pub fn parse_flags(flags: &[String]) -> Flags {

fn handle_config<'a>(flags: &mut Flags<'a>, file: Option<&'a String>) {
if file.is_none() {
ERROR!(
"/tmp/reset_lib_log",
"No file provided!",
ErrorLevel::Critical
);
ERROR!("No file provided!", ErrorLevel::Critical);
return;
}
let path = file.unwrap();
let data = fs::metadata(path);
if data.is_err() {
ERROR!(
"/tmp/reset_lib_log",
"Provided path does not exist!",
ErrorLevel::Critical
);
ERROR!("Provided path does not exist!", ErrorLevel::Critical);
return;
}
let data = data.unwrap();
if !data.is_file() {
ERROR!(
"/tmp/reset_lib_log",
"Provided path is not a file!",
ErrorLevel::Critical
);
ERROR!("Provided path is not a file!", ErrorLevel::Critical);
return;
}
flags.0.push(Flag::ConfigDir(path));
}

fn handle_plugins<'a>(flags: &mut Flags<'a>, file: Option<&'a String>) {
if file.is_none() {
ERROR!(
"/tmp/reset_lib_log",
"No directory provided!",
ErrorLevel::Critical
);
ERROR!("No directory provided!", ErrorLevel::Critical);
return;
}
let path = file.unwrap();
let data = fs::metadata(path);
if data.is_err() {
ERROR!(
"/tmp/reset_lib_log",
"Provided path does not exist!",
ErrorLevel::Critical
);
ERROR!("Provided path does not exist!", ErrorLevel::Critical);
return;
}
let data = data.unwrap();
if !data.is_dir() {
ERROR!(
"/tmp/reset_lib_log",
"Provided path is not a file!",
ErrorLevel::Critical
);
ERROR!("Provided path is not a file!", ErrorLevel::Critical);
return;
}
flags.0.push(Flag::PluginDir(path));
Expand All @@ -131,7 +107,6 @@ fn handle_plugins<'a>(flags: &mut Flags<'a>, file: Option<&'a String>) {
fn handle_other<'a>(flags: &mut Flags<'a>, flag: &'a str, values: &mut Iter<String>) {
if !flag.starts_with('-') || !flag.starts_with("--") {
ERROR!(
"/tmp/reset_lib_log",
format!("Expected a flag, got a regular string instead: {}", flag),
ErrorLevel::Critical
);
Expand Down
14 changes: 7 additions & 7 deletions src/utils/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ macro_rules! LOG {
#[macro_export]
#[cfg(debug_assertions)]
macro_rules! LOG {
($log_file:expr, $message:expr) => {{
write_log_to_file!($message, $log_file);
($message:expr) => {{
write_log_to_file!($message);
println!("LOG: {}", $message);
}};
}
Expand All @@ -22,24 +22,24 @@ macro_rules! ERROR {
#[macro_export]
#[cfg(debug_assertions)]
macro_rules! ERROR {
($log_file:expr, $message:expr, $level:expr) => {{
write_log_to_file!($message, $log_file);
($message:expr, $level:expr) => {{
write_log_to_file!($message);
match $level {
ErrorLevel::Recoverable => println!("Minor Error: {}", $message),
ErrorLevel::PartialBreakage => println!("Partial Error: {}", $message),
ErrorLevel::Critical => println!("Critical Error: {}", $message),
};
}};
}

#[macro_export]
macro_rules! write_log_to_file {
($message:expr, $log_file:expr) => {{
($message:expr) => {{
use std::{fs::OpenOptions, io::Write};
const VERSION: &str = env!("CARGO_PKG_NAME");
let mut file = OpenOptions::new()
.append(true)
.create(true)
.open($log_file)
.open("/tmp/".to_string() + VERSION + "_log")
.expect("Could not open log file");
file.write_all($message.as_bytes())
.expect("Could not write to log file");
Expand Down

0 comments on commit 7a200b0

Please sign in to comment.