|
|
|
@ -8,6 +8,7 @@ use std::{
|
|
|
|
|
PathBuf,
|
|
|
|
|
Path,
|
|
|
|
|
},
|
|
|
|
|
marker::PhantomData,
|
|
|
|
|
};
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
|
@ -24,9 +25,13 @@ fn extra_args() -> &'static str
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref EXTRA: &'static str = {
|
|
|
|
|
let work = || -> Result<String, std::fmt::Error> {
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
|
use std::fmt::Write as _;
|
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
|
let mut output = String::new();
|
|
|
|
|
#[cfg(feature="progress")] writeln!(output, " --no-progress Do not display progress bar")?;
|
|
|
|
|
#[cfg(feature="colour")] writeln!(output, " --no-colour Do not display terminal colours")?;
|
|
|
|
|
#[cfg(feature="colour")] writeln!(output, " --colour Always display terminal colour, even if env flags tell us not to")?;
|
|
|
|
|
Ok(output)
|
|
|
|
|
};
|
|
|
|
|
match work() {
|
|
|
|
@ -41,54 +46,55 @@ fn extra_args() -> &'static str
|
|
|
|
|
&EXTRA[..]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
|
mod feature
|
|
|
|
|
{
|
|
|
|
|
use cfg_if::cfg_if;
|
|
|
|
|
#[macro_export] macro_rules! check {
|
|
|
|
|
(on $name:literal) => {
|
|
|
|
|
(on $name:literal, $desc:expr) => {
|
|
|
|
|
if cfg!(feature = $name) {
|
|
|
|
|
feature::on($name, true);
|
|
|
|
|
feature::on($name, true, $desc);
|
|
|
|
|
} else {
|
|
|
|
|
feature::off($name, false);
|
|
|
|
|
feature::off($name, false, $desc);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(off $name:literal) => {
|
|
|
|
|
(off $name:literal, $desc:expr) => {
|
|
|
|
|
if cfg!(feature = $name) {
|
|
|
|
|
feature::on($name, false);
|
|
|
|
|
feature::on($name, false, $desc);
|
|
|
|
|
} else {
|
|
|
|
|
feature::off($name, true);
|
|
|
|
|
feature::off($name, true, $desc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub fn on(name: impl AsRef<str>, default: bool)
|
|
|
|
|
pub fn on(name: impl AsRef<str>, default: bool, desc: impl AsRef<str>)
|
|
|
|
|
{
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature="colour")] {
|
|
|
|
|
use recolored::Colorize;
|
|
|
|
|
if default {
|
|
|
|
|
println!(" {}", format!("+{}", name.as_ref()).red());
|
|
|
|
|
println!(" {} {}", format!("+{}", name.as_ref()).red(), desc.as_ref().bright_black());
|
|
|
|
|
} else {
|
|
|
|
|
println!(" {}", format!("+{}", name.as_ref()).bright_red());
|
|
|
|
|
println!(" {} {}", format!("+{}", name.as_ref()).bright_red(), desc.as_ref());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
println!(" +{}", name.as_ref())
|
|
|
|
|
println!(" +{} {}", name.as_ref(), desc.as_ref())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn off(name: impl AsRef<str>, default: bool)
|
|
|
|
|
pub fn off(name: impl AsRef<str>, default: bool, desc: impl AsRef<str>)
|
|
|
|
|
{
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature="colour")] {
|
|
|
|
|
use recolored::Colorize;
|
|
|
|
|
if default {
|
|
|
|
|
println!(" {}", format!("-{}", name.as_ref()).blue());
|
|
|
|
|
println!(" {} {}", format!("-{}", name.as_ref()).blue(), desc.as_ref().bright_black());
|
|
|
|
|
} else {
|
|
|
|
|
println!(" {}", format!("-{}", name.as_ref()).bright_blue());
|
|
|
|
|
println!(" {} {}", format!("-{}", name.as_ref()).bright_blue(), desc.as_ref());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
println!(" -{}", name.as_ref())
|
|
|
|
|
println!(" -{} {}", name.as_ref(), desc.as_ref())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -96,10 +102,10 @@ mod feature
|
|
|
|
|
|
|
|
|
|
fn comp_flags()
|
|
|
|
|
{
|
|
|
|
|
check!(on "splash");
|
|
|
|
|
check!(on "colour");
|
|
|
|
|
check!(on "progress");
|
|
|
|
|
check!(off "threads");
|
|
|
|
|
check!(on "splash", "Show splash-screen");
|
|
|
|
|
check!(on "colour", "Enable coloured output");
|
|
|
|
|
check!(on "progress", "Enable progress bar");
|
|
|
|
|
check!(off "threads", "Enable threaded scheduler (usually not needed).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn usage() -> !
|
|
|
|
@ -111,15 +117,15 @@ pub fn usage() -> !
|
|
|
|
|
Usage: {prog} --help
|
|
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
|
- Stop parsing args here.
|
|
|
|
|
--max-children <number> Max subprocesses allowed to live at once. Infinite by default.
|
|
|
|
|
-m Limit subprocesses to number of CPU cores.
|
|
|
|
|
--recursive <number> Recurse up to `<number>` times. Must be at least `1`. Default is off.
|
|
|
|
|
-r Resurse infinitely.
|
|
|
|
|
{extra}
|
|
|
|
|
- Stop parsing args here.
|
|
|
|
|
|
|
|
|
|
ENVIRONMENT VARS:
|
|
|
|
|
LEANIFY=<process name> Path to leanify executable, defaults to looking in `PATH' if set.
|
|
|
|
|
", prog = program_name(), extra = &extra_args()[..extra_args().len()-1]);
|
|
|
|
|
", prog = program_name(), extra = extra_args());
|
|
|
|
|
println!("Compiled with:");
|
|
|
|
|
comp_flags();
|
|
|
|
|
|
|
|
|
@ -132,6 +138,8 @@ pub enum Error {
|
|
|
|
|
#[cfg(not(nightly))] BadNumber(()),
|
|
|
|
|
NoExist(PathBuf),
|
|
|
|
|
Walking(dir::Error),
|
|
|
|
|
|
|
|
|
|
Other(&'static str),
|
|
|
|
|
NoFiles,
|
|
|
|
|
}
|
|
|
|
|
impl std::error::Error for Error{}
|
|
|
|
@ -158,6 +166,7 @@ impl std::fmt::Display for Error
|
|
|
|
|
Self::NoExist(path) => write!(f, "path {:?} does not exist", path),
|
|
|
|
|
Self::NoFiles => write!(f, "need at least one argument"),
|
|
|
|
|
Self::Walking(dir) => write!(f, "error walking directory structure(s): {}", dir),
|
|
|
|
|
Self::Other(msg) => write!(f, "{}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -178,6 +187,13 @@ pub struct Flags
|
|
|
|
|
{
|
|
|
|
|
/// Display the progress bar
|
|
|
|
|
#[cfg(feature="progress")] pub progress: bool,
|
|
|
|
|
/// Force use of colour
|
|
|
|
|
#[cfg(feature="colour")] pub coloured: Option<bool>,
|
|
|
|
|
/// Limit max children to this number
|
|
|
|
|
pub hard_limit: Option<NonZeroUsize>,
|
|
|
|
|
|
|
|
|
|
/// To shut the linter up when we have no elements here
|
|
|
|
|
_data: PhantomData<()>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Flags
|
|
|
|
@ -187,6 +203,10 @@ impl Default for Flags
|
|
|
|
|
{
|
|
|
|
|
Self {
|
|
|
|
|
#[cfg(feature="progress")] progress: true,
|
|
|
|
|
#[cfg(feature="colour")] coloured: None,
|
|
|
|
|
hard_limit: None,
|
|
|
|
|
|
|
|
|
|
_data: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -254,6 +274,13 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"-m" => {
|
|
|
|
|
cfg.flags.hard_limit = NonZeroUsize::new(num_cpus::get());
|
|
|
|
|
if cfg.flags.hard_limit.is_none() {
|
|
|
|
|
return Err(Error::Other("-m: Could not determine number of CPUs, try setting max children manually with `--max-children`"));
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
},
|
|
|
|
|
"--recursive" => {
|
|
|
|
|
if let Some(nzi) = args.next() {
|
|
|
|
|
cfg.recursive = Some(nzi.parse()?);
|
|
|
|
@ -265,6 +292,16 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
cfg.flags.progress = false;
|
|
|
|
|
continue;
|
|
|
|
|
},
|
|
|
|
|
#[cfg(feature="colour")]
|
|
|
|
|
"--no-colour" => {
|
|
|
|
|
cfg.flags.coloured = Some(false);
|
|
|
|
|
continue;
|
|
|
|
|
},
|
|
|
|
|
#[cfg(feature="colour")]
|
|
|
|
|
"--colour" => {
|
|
|
|
|
cfg.flags.coloured = Some(true);
|
|
|
|
|
continue;
|
|
|
|
|
},
|
|
|
|
|
"-r" => {
|
|
|
|
|
cfg.recursive = None;
|
|
|
|
|
},
|
|
|
|
|