bugfix, implemented verbose logging cli option
Some checks failed
Test the running changes / Test (push) Failing after 38s
Some checks failed
Test the running changes / Test (push) Failing after 38s
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//! A "Markdown" parser and HTML generator. Part of a static site generator `marksmith-rs`.
|
//! A "Markdown" parser and HTML generator. Part of a static site generator `marksmith-rs`.
|
||||||
//! Not following any standards, only vibes.
|
//! Not following any standards, only vibes.
|
||||||
|
|
||||||
#![deny(unused_imports)]
|
#![deny(dead_code, unused_imports)]
|
||||||
#![allow(clippy::needless_pass_by_value)]
|
#![allow(clippy::needless_pass_by_value)]
|
||||||
|
|
||||||
use fstools::crawl_fs;
|
use fstools::crawl_fs;
|
||||||
@@ -107,6 +107,7 @@ pub enum Error {
|
|||||||
InDirIsNotDir,
|
InDirIsNotDir,
|
||||||
OutDirIsNotEmpty,
|
OutDirIsNotEmpty,
|
||||||
OutDirIsNotDir,
|
OutDirIsNotDir,
|
||||||
|
OutDirFileOverwriteWithoutForce,
|
||||||
OutDirFileDeleteNotAllowed,
|
OutDirFileDeleteNotAllowed,
|
||||||
OutDirDirectoryInPlaceOfFile,
|
OutDirDirectoryInPlaceOfFile,
|
||||||
FileRead,
|
FileRead,
|
||||||
@@ -162,8 +163,12 @@ pub fn generate(indir: &PathBuf, outdir: &PathBuf, force: bool) -> Result<()> {
|
|||||||
// check if path exists
|
// check if path exists
|
||||||
if newpath.exists() {
|
if newpath.exists() {
|
||||||
// remove if is file and if force, otherwise error
|
// remove if is file and if force, otherwise error
|
||||||
if newpath.is_file() && force {
|
if newpath.is_file() {
|
||||||
fs::remove_file(&newpath).map_err(|_e| Error::OutDirFileDeleteNotAllowed)?;
|
if force {
|
||||||
|
fs::remove_file(&newpath).map_err(|_e| Error::OutDirFileDeleteNotAllowed)?;
|
||||||
|
} else {
|
||||||
|
Err(Error::OutDirFileOverwriteWithoutForce)?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(Error::OutDirDirectoryInPlaceOfFile)?;
|
Err(Error::OutDirDirectoryInPlaceOfFile)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
//! Simple and program specific command line argument parsing solution.
|
//! Simple and program specific command line argument parsing solution.
|
||||||
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
use crate::error::ErrorKind;
|
use crate::error::ErrorKind;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
pub static VERBOSE: OnceLock<bool> = OnceLock::new();
|
||||||
|
|
||||||
pub struct ProgramArgs {
|
pub struct ProgramArgs {
|
||||||
pub outdir: PathBuf,
|
pub outdir: PathBuf,
|
||||||
@@ -12,6 +13,7 @@ pub struct ProgramArgs {
|
|||||||
pub generate: bool,
|
pub generate: bool,
|
||||||
pub force: bool,
|
pub force: bool,
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
|
pub verbose: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ProgramArgs {
|
impl Default for ProgramArgs {
|
||||||
@@ -22,6 +24,7 @@ impl Default for ProgramArgs {
|
|||||||
generate: false,
|
generate: false,
|
||||||
force: false,
|
force: false,
|
||||||
addr: "0.0.0.0:8080".to_string(),
|
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,
|
"-g" => a.generate = true,
|
||||||
"-f" => a.force = true,
|
"-f" => a.force = true,
|
||||||
|
"-v" => {
|
||||||
|
a.verbose = true;
|
||||||
|
VERBOSE.get_or_init(|| true);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
a.outdir = v.into();
|
a.outdir = v.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VERBOSE.get_or_init(|| false);
|
||||||
Ok(a)
|
Ok(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::fmt::Display;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub enum Level {
|
pub enum Level {
|
||||||
Error,
|
Error,
|
||||||
Warn,
|
Warn,
|
||||||
@@ -30,13 +31,15 @@ impl Display for Level {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
($level:expr, $($arg:tt)*) => {{
|
($level:expr, $($arg:tt)*) => {{
|
||||||
println!(
|
if $level != Level::Debug || crate::args::VERBOSE.get().unwrap().to_owned() {
|
||||||
"{} {}:{}:{}: {}",
|
println!(
|
||||||
$level,
|
"{} {}:{}:{}: {}",
|
||||||
std::module_path!(),
|
$level,
|
||||||
std::file!(),
|
std::module_path!(),
|
||||||
std::line!(),
|
std::file!(),
|
||||||
format!($($arg)*)
|
std::line!(),
|
||||||
);
|
format!($($arg)*)
|
||||||
|
);
|
||||||
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ impl HttpResponse {
|
|||||||
let _ = std::io::Read::read(stream, &mut [0u8; 1]);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user