From 4ee524d8595af5be0dcc2f6fce191b9474abcc2b Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 17 Feb 2021 00:38:38 +0000 Subject: [PATCH] fix feature-dependant argument options --- src/arg.rs | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/arg.rs b/src/arg.rs index 715cfed..ebc0c41 100644 --- a/src/arg.rs +++ b/src/arg.rs @@ -1,6 +1,7 @@ //! Argument parsing and handling use super::*; use std::num::NonZeroUsize; +use std::fmt; use config::Config; @@ -21,6 +22,40 @@ pub fn program_name() -> &'static str eprintln!("Made by {} with <3.\n Licensed with GPL v3.0 +", env!("CARGO_PKG_AUTHORS")); } +const OPTIONS_NORMAL: &'static [&'static str] = &[ + "--recursive Set max directory recursion depth limit (1 = No recursion (default), 0 = Unlimited recursion).", + "-r Set unlimited directory recursion depth. (same as `--recursive 0`).", + "--threads Limit the maximum number of tasks allowed to process concurrently (Set to 0 for unlimited.)", + "-M Set number of parallel running tasks to unlimited. (Same as `--threads 0`). (default).", + "-m Limit number of parallel tasks to the number of active CPU processors.", + "-q Quiet mode. Don't output info messages about successful `stat`ing.", + "-Q Silent mode. Don't output any messages.", + "-v Verbose mode. Output extra information.", + #[cfg(feature="inspect")] "--save Dump the collected data to this file for further inspection.", + #[cfg(feature="inspect")] "-D Dump the collected data to `stdout` (see `--save`.)", + "- Stop parsing arguments, treat all the rest as paths.", +]; + +fn get_opt_normal() -> impl fmt::Display +{ + #[derive(Debug)] + struct Opt; + + impl fmt::Display for Opt + { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + for line in OPTIONS_NORMAL.iter() + { + writeln!(f, " {}", line)?; + } + Ok(()) + } + } + + Opt +} + /// Print usage message pub fn usage() { @@ -33,17 +68,7 @@ pub fn usage() println!("{} --help", program_name()); println!(r#" OPTIONS: - --recursive Set max directory recursion depth limit (1 = No recursion (default), 0 = Unlimited recursion). - -r Set unlimited directory recursion depth. (same as `--recursive 0`). - --threads Limit the maximum number of tasks allowed to process concurrently (Set to 0 for unlimited.) - -M Set number of parallel running tasks to unlimited. (Same as `--threads 0`). (default). - -m Limit number of parallel tasks to the number of active CPU processors. - -q Quiet mode. Don't output info messages about successful `stat`ing. - -Q Silent mode. Don't output any messages. - -v Verbose mode. Output extra information. - --save Dump the collected data to this file for further inspection (only available when compiled with feature `inspect`) - -D Dump the collected data to `stdout` (see `--save`) (only available when compiled with feature `inspect`) - - Stop parsing arguments, treat all the rest as paths. +{} --help Print this message and exit. @@ -52,7 +77,7 @@ NOTES: If parallelism is set to unlimited, there can be a huge syscall overhead. It is recommended to use `-m`. Symlinks are ignored while collection stat data. They will fail with message 'Unknown file type'. Symlinks are generally very small in the actual data they contain themselves, so this is *usually* unimportant. -"#); +"#, get_opt_normal()); } /// Print usage message then exit with code 1.