bugfix, implemented verbose logging cli option
Some checks failed
Test the running changes / Test (push) Failing after 38s

This commit is contained in:
2025-11-17 00:48:23 +02:00
parent 6fa26f8a33
commit 33bfff2e98
4 changed files with 33 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
//! A "Markdown" parser and HTML generator. Part of a static site generator `marksmith-rs`.
//! Not following any standards, only vibes.
#![deny(unused_imports)]
#![deny(dead_code, unused_imports)]
#![allow(clippy::needless_pass_by_value)]
use fstools::crawl_fs;
@@ -107,6 +107,7 @@ pub enum Error {
InDirIsNotDir,
OutDirIsNotEmpty,
OutDirIsNotDir,
OutDirFileOverwriteWithoutForce,
OutDirFileDeleteNotAllowed,
OutDirDirectoryInPlaceOfFile,
FileRead,
@@ -162,8 +163,12 @@ pub fn generate(indir: &PathBuf, outdir: &PathBuf, force: bool) -> Result<()> {
// check if path exists
if newpath.exists() {
// remove if is file and if force, otherwise error
if newpath.is_file() && force {
if newpath.is_file() {
if force {
fs::remove_file(&newpath).map_err(|_e| Error::OutDirFileDeleteNotAllowed)?;
} else {
Err(Error::OutDirFileOverwriteWithoutForce)?;
}
} else {
Err(Error::OutDirDirectoryInPlaceOfFile)?;
}

View File

@@ -1,10 +1,11 @@
//! Simple and program specific command line argument parsing solution.
use std::path::PathBuf;
use crate::error::Error;
use crate::error::ErrorKind;
use std::path::PathBuf;
use std::sync::OnceLock;
pub static VERBOSE: OnceLock<bool> = OnceLock::new();
pub struct ProgramArgs {
pub outdir: PathBuf,
@@ -12,6 +13,7 @@ pub struct ProgramArgs {
pub generate: bool,
pub force: bool,
pub addr: String,
pub verbose: bool,
}
impl Default for ProgramArgs {
@@ -22,6 +24,7 @@ impl Default for ProgramArgs {
generate: false,
force: false,
addr: "0.0.0.0:8080".to_string(),
verbose: false,
}
}
}
@@ -50,11 +53,16 @@ impl TryFrom<std::env::Args> for ProgramArgs {
}
"-g" => a.generate = true,
"-f" => a.force = true,
"-v" => {
a.verbose = true;
VERBOSE.get_or_init(|| true);
}
_ => {
a.outdir = v.into();
}
}
}
VERBOSE.get_or_init(|| false);
Ok(a)
}
}

View File

@@ -2,6 +2,7 @@ use std::fmt::Display;
#[derive(Debug)]
#[allow(dead_code)]
#[derive(PartialEq)]
pub enum Level {
Error,
Warn,
@@ -30,6 +31,7 @@ impl Display for Level {
#[macro_export]
macro_rules! log {
($level:expr, $($arg:tt)*) => {{
if $level != Level::Debug || crate::args::VERBOSE.get().unwrap().to_owned() {
println!(
"{} {}:{}:{}: {}",
$level,
@@ -38,5 +40,6 @@ macro_rules! log {
std::line!(),
format!($($arg)*)
);
}
}};
}

View File

@@ -119,7 +119,9 @@ impl HttpResponse {
let _ = std::io::Read::read(stream, &mut [0u8; 1]);
*/
log!(Level::Info, "\n{}", &self);
// todo better verbose tracking
log!(Level::Info, "{} {}", self.version, self.status);
log!(Level::Debug, "\n{}", &self);
Ok(())
}