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