added config speicifc printing macros

fuck_this_bullshit
Avril 4 years ago
parent 9f4a0faa68
commit ec35671398
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -54,6 +54,8 @@ pub struct Config
pub recursive: Recursion, pub recursive: Recursion,
pub max_tasks: Option<NonZeroUsize>, pub max_tasks: Option<NonZeroUsize>,
pub silent: bool,
#[cfg(feature="inspect")] #[cfg(feature="inspect")]
pub serialise_output: Option<Option<PathBuf>>, // Some(None) means dump to `stdout` pub serialise_output: Option<Option<PathBuf>>, // Some(None) means dump to `stdout`
} }
@ -94,6 +96,7 @@ impl Default for Config
paths: Vec::new(), paths: Vec::new(),
recursive: Default::default(), recursive: Default::default(),
max_tasks: None, //max_tasks_cpus(), max_tasks: None, //max_tasks_cpus(),
silent: false,
#[cfg(feature="inspect")] #[cfg(feature="inspect")]
serialise_output: None, serialise_output: None,
} }
@ -145,3 +148,30 @@ impl fmt::Display for InvalidConfigError
} }
} }
} }
/// Print an error line in accordance with `Config`'s output directives.
#[macro_export] macro_rules! cfg_eprintln {
($cfg:expr, $fmt:literal $($tt:tt)*) => {
{
if !$cfg.silent {
eprintln!($fmt $($tt)*);
}
}
}
}
/// Print a line in accordance with `Config`'s output directives.
#[macro_export] macro_rules! cfg_println {
($cfg:expr, $fmt:literal $($tt:tt)*) => {
{
let cfg = &$cfg;
if !cfg.silent {
if cfg.is_using_stdout() {
eprintln!($fmt $($tt)*);
} else {
println!($fmt $($tt)*);
}
}
}
}
}

@ -88,11 +88,7 @@ fn walk(state: State, root: PathBuf, root_ino: INode) -> BoxFuture<'static, Hash
async move { async move {
{ {
let _guard = state.lock().enter().await; let _guard = state.lock().enter().await;
if state.config().is_using_stdout() { cfg_println!(state.config(), " -> {:?}", root);
eprintln!(" -> {:?}", root);
} else {
println!(" -> {:?}", root);
}
match fs::read_dir(&root).await match fs::read_dir(&root).await
{ {
Ok(mut dir) => { Ok(mut dir) => {

Loading…
Cancel
Save