diff --git a/completions/_dust b/completions/_dust index 41d67fea..09c1ec9c 100644 --- a/completions/_dust +++ b/completions/_dust @@ -19,14 +19,14 @@ _dust() { '--depth=[Depth to show]: : ' \ '-n+[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \ '--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]: : ' \ -'-X+[Exclude any file or directory with this name]: : ' \ -'--ignore-directory=[Exclude any file or directory with this name]: : ' \ +'*-X+[Exclude any file or directory with this name]: : ' \ +'*--ignore-directory=[Exclude any file or directory with this name]: : ' \ '-z+[Minimum size file to include in output]: : ' \ '--min-size=[Minimum size file to include in output]: : ' \ -'(-e --filter -t --file_types)-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \ -'(-e --filter -t --file_types)--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \ -'(-t --file_types)-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \ -'(-t --file_types)--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \ +'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \ +'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]: : ' \ +'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \ +'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]: : ' \ '-w+[Specify width of output overriding the auto detection of terminal width]: : ' \ '--terminal_width=[Specify width of output overriding the auto detection of terminal width]: : ' \ '-p[Subdirectories will not have their path shortened]' \ @@ -43,15 +43,10 @@ _dust() { '--no-colors[No colors will be printed (Useful for commands like\: watch)]' \ '-b[No percent bars or percentages will be displayed]' \ '--no-percent-bars[No percent bars or percentages will be displayed]' \ -<<<<<<< HEAD '-B[percent bars moved to right side of screen]' \ '--bars-on-right[percent bars moved to right side of screen]' \ -'-R[For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)]' \ -'--screen-reader[For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)]' \ -======= '-R[For screen readers. Removes bars. Adds new column\: depth level (May want to use -p too for full path)]' \ '--screen-reader[For screen readers. Removes bars. Adds new column\: depth level (May want to use -p too for full path)]' \ ->>>>>>> bad9758 (dependency: upgrade to clap 4) '--skip-total[No total row will be displayed]' \ '-f[Directory '\''size'\'' is number of child files instead of disk size]' \ '--filecount[Directory '\''size'\'' is number of child files instead of disk size]' \ @@ -71,7 +66,7 @@ _dust() { '--help[Print help]' \ '-V[Print version]' \ '--version[Print version]' \ -'*::inputs:' \ +'*::params:' \ && ret=0 } diff --git a/completions/_dust.ps1 b/completions/_dust.ps1 index ddf016fb..07b7d2b5 100644 --- a/completions/_dust.ps1 +++ b/completions/_dust.ps1 @@ -49,9 +49,9 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock { [CompletionResult]::new('--no-colors', 'no-colors', [CompletionResultType]::ParameterName, 'No colors will be printed (Useful for commands like: watch)') [CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'No percent bars or percentages will be displayed') [CompletionResult]::new('--no-percent-bars', 'no-percent-bars', [CompletionResultType]::ParameterName, 'No percent bars or percentages will be displayed') - [CompletionResult]::new('-B', 'B', [CompletionResultType]::ParameterName, 'percent bars moved to right side of screen') + [CompletionResult]::new('-B', 'B ', [CompletionResultType]::ParameterName, 'percent bars moved to right side of screen') [CompletionResult]::new('--bars-on-right', 'bars-on-right', [CompletionResultType]::ParameterName, 'percent bars moved to right side of screen') - [CompletionResult]::new('-R', 'R', [CompletionResultType]::ParameterName, 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)') + [CompletionResult]::new('-R', 'R ', [CompletionResultType]::ParameterName, 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)') [CompletionResult]::new('--screen-reader', 'screen-reader', [CompletionResultType]::ParameterName, 'For screen readers. Removes bars. Adds new column: depth level (May want to use -p too for full path)') [CompletionResult]::new('--skip-total', 'skip-total', [CompletionResultType]::ParameterName, 'No total row will be displayed') [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Directory ''size'' is number of child files instead of disk size') diff --git a/completions/dust.bash b/completions/dust.bash index 02b75cdb..e427aff2 100644 --- a/completions/dust.bash +++ b/completions/dust.bash @@ -19,7 +19,7 @@ _dust() { case "${cmd}" in dust) - opts="-h -V -d -n -p -X -L -x -s -r -c -b -B -z -R -f -i -v -e -t -w -H -P -D -F --help --version --depth --number-of-lines --full-paths --ignore-directory --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --no-progress --only-dir --only-file ..." + opts="-d -n -p -X -L -x -s -r -c -b -B -z -R -f -i -v -e -t -w -H -P -D -F -h -V --depth --number-of-lines --full-paths --ignore-directory --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore_hidden --invert-filter --filter --file_types --terminal_width --si --no-progress --only-dir --only-file --help --version [params]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/man-page/dust.1 b/man-page/dust.1 index fa5bae6c..2552ba34 100644 --- a/man-page/dust.1 +++ b/man-page/dust.1 @@ -1,10 +1,10 @@ .ie \n(.g .ds Aq \(aq .el .ds Aq ' -.TH Dust 1 "Dust 0.8.6" +.TH Dust 1 "Dust 0.8.6" .SH NAME Dust \- Like du but more intuitive .SH SYNOPSIS -\fBDust\fR [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-b\fR|\fB\-\-no\-percent\-bars\fR] [\fB\-B\fR|\fB\-\-bars\-on\-right\fR] [\fB\-z\fR|\fB\-\-min\-size\fR] [\fB\-R\fR|\fB\-\-screen\-reader\fR] [\fB\-\-skip\-total\fR] [\fB\-f\fR|\fB\-\-filecount\fR] [\fB\-i\fR|\fB\-\-ignore_hidden\fR] [\fB\-v\fR|\fB\-\-invert\-filter\fR] [\fB\-e\fR|\fB\-\-filter\fR] [\fB\-t\fR|\fB\-\-file_types\fR] [\fB\-w\fR|\fB\-\-terminal_width\fR] [\fB\-H\fR|\fB\-\-si\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fIinputs\fR] +\fBDust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-b\fR|\fB\-\-no\-percent\-bars\fR] [\fB\-B\fR|\fB\-\-bars\-on\-right\fR] [\fB\-z\fR|\fB\-\-min\-size\fR] [\fB\-R\fR|\fB\-\-screen\-reader\fR] [\fB\-\-skip\-total\fR] [\fB\-f\fR|\fB\-\-filecount\fR] [\fB\-i\fR|\fB\-\-ignore_hidden\fR] [\fB\-v\fR|\fB\-\-invert\-filter\fR] [\fB\-e\fR|\fB\-\-filter\fR] [\fB\-t\fR|\fB\-\-file_types\fR] [\fB\-w\fR|\fB\-\-terminal_width\fR] [\fB\-H\fR|\fB\-\-si\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIparams\fR] .SH DESCRIPTION Like du but more intuitive .SH OPTIONS @@ -58,10 +58,10 @@ Directory \*(Aqsize\*(Aq is number of child files instead of disk size Do not display hidden files .TP \fB\-v\fR, \fB\-\-invert\-filter\fR -Exclude filepaths matching this regex. To ignore png files type: \-v "\\.png$" +Exclude filepaths matching this regex. To ignore png files type: \-v "\\.png$" .TP \fB\-e\fR, \fB\-\-filter\fR -Only include filepaths matching this regex. For png files type: \-e "\\.png$" +Only include filepaths matching this regex. For png files type: \-e "\\.png$" .TP \fB\-t\fR, \fB\-\-file_types\fR show only these file types @@ -87,7 +87,7 @@ Print help \fB\-V\fR, \fB\-\-version\fR Print version .TP -[\fIinputs\fR] +[\fIparams\fR] .SH VERSION v0.8.6 diff --git a/src/cli.rs b/src/cli.rs index 03d37159..1dcd3d45 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -use clap::{Arg, Command, value_parser}; +use clap::{value_parser, Arg, Command}; // For single thread mode set this variable on your command line: // export RAYON_NUM_THREADS=1 @@ -35,7 +35,7 @@ pub fn build_cli() -> Command { Arg::new("ignore_directory") .short('X') .long("ignore-directory") - .num_args(1..) + .action(clap::ArgAction::Append) .help("Exclude any file or directory with this name"), ) .arg( @@ -84,6 +84,7 @@ pub fn build_cli() -> Command { Arg::new("bars_on_right") .short('B') .long("bars-on-right") + .action(clap::ArgAction::SetTrue) .help("percent bars moved to right side of screen"), ) .arg( @@ -124,7 +125,7 @@ pub fn build_cli() -> Command { Arg::new("invert_filter") .short('v') .long("invert-filter") - .num_args(1..) + .action(clap::ArgAction::Append) .conflicts_with("filter") .conflicts_with("types") .help("Exclude filepaths matching this regex. To ignore png files type: -v \"\\.png$\" "), @@ -133,7 +134,7 @@ pub fn build_cli() -> Command { Arg::new("filter") .short('e') .long("filter") - .num_args(1..) + .action(clap::ArgAction::Append) .conflicts_with("types") .help("Only include filepaths matching this regex. For png files type: -e \"\\.png$\" "), ) @@ -185,5 +186,6 @@ pub fn build_cli() -> Command { .action(clap::ArgAction::SetTrue) .help("Only files will be displayed. (Finds your largest files)"), ) - .arg(Arg::new("inputs").num_args(1..)) + .arg(Arg::new("params").num_args(1..) + .value_parser(value_parser!(String))) } diff --git a/src/config.rs b/src/config.rs index 6df5e292..99c92869 100644 --- a/src/config.rs +++ b/src/config.rs @@ -93,7 +93,7 @@ impl Config { Some(true) == self.only_file || options.get_flag("only_file") } pub fn get_bars_on_right(&self, options: &ArgMatches) -> bool { - Some(true) == self.bars_on_right || options.is_present("bars_on_right") + Some(true) == self.bars_on_right || options.get_flag("bars_on_right") } } @@ -156,7 +156,7 @@ pub fn get_config() -> Config { mod tests { #[allow(unused_imports)] use super::*; - use clap::{Arg, ArgMatches, Command, ArgAction, value_parser}; + use clap::{value_parser, Arg, ArgMatches, Command}; #[test] fn test_conversion() { @@ -176,10 +176,10 @@ mod tests { ..Default::default() }; assert_eq!(c._get_min_size(None, false), Some(1024)); - assert_eq!(c._get_min_size(Some(&"2K"), false), Some(2048)); + assert_eq!(c._get_min_size(Some(&"2K".into()), false), Some(2048)); assert_eq!(c._get_min_size(None, true), Some(1000)); - assert_eq!(c._get_min_size(Some(&"2K"), true), Some(2000)); + assert_eq!(c._get_min_size(Some(&"2K".into()), true), Some(2000)); } #[test] @@ -213,25 +213,12 @@ mod tests { fn get_args(args: Vec<&str>) -> ArgMatches { Command::new("Dust") - .arg(Arg::new("depth").long("depth").num_args(1).value_parser(value_parser!(usize))) + .arg( + Arg::new("depth") + .long("depth") + .num_args(1) + .value_parser(value_parser!(usize)), + ) .get_matches_from(args) } - - #[test] - fn test_fuck() { - let m = Command::new("myprog") - .arg(Arg::new("ports") - .action(ArgAction::Append) - .value_parser(value_parser!(usize)) - .short('p') - .required(true)) - .get_matches_from(vec![ - "myprog", "-p", "22", "-p", "80", "-p", "2020" - ]); - let vals: Vec = m.get_many("ports") - .expect("`port`is required") - .copied() - .collect(); - assert_eq!(vals, [22, 80, 2020]); - } } diff --git a/src/main.rs b/src/main.rs index 3b4eeb12..236a2742 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,8 +102,8 @@ fn main() { let options = build_cli().get_matches(); let config = get_config(); - let target_dirs = match options.get_many("inputs") { - Some(values) => values.copied().collect(), + let target_dirs = match options.get_many::("params") { + Some(values) => values.map(|v| v.as_str()).collect::>(), None => vec!["."], }; @@ -112,9 +112,9 @@ fn main() { let filter_regexs = get_regex_value(options.get_many("filter")); let invert_filter_regexs = get_regex_value(options.get_many("invert_filter")); - let terminal_width :usize = match options.get_one::("width") { + let terminal_width: usize = match options.get_one::("width") { Some(&val) => val, - None => get_width_of_terminal() + None => get_width_of_terminal(), }; let depth = config.get_depth(&options); @@ -122,7 +122,7 @@ fn main() { // If depth is set, then we set the default number_of_lines to be max // instead of screen height - let number_of_lines = match options.get_one::("number_of_lines"){ + let number_of_lines = match options.get_one::("number_of_lines") { Some(&val) => val, None => { if depth != usize::MAX { @@ -135,15 +135,14 @@ fn main() { let no_colors = init_color(config.get_no_colors(&options)); - // let ix : Option>> = options.get_many("ignore_directory"); - - let ix2: Vec<&str> = match options.get_many("ignore_directory") { - Some(values) => values.copied().collect::>(), + let ignore_directories = match options.get_many::("ignore_directory") { + Some(values) => values + .map(|v| v.as_str()) + .map(PathBuf::from) + .collect::>(), None => vec![], }; - let ignore_directories =ix2.into_iter().map(PathBuf::from); - let by_filecount = options.get_flag("by_filecount"); let limit_filesystem = options.get_flag("limit_filesystem"); let follow_links = options.get_flag("dereference_links"); @@ -154,6 +153,7 @@ fn main() { .unwrap_or_default(); let ignored_full_path: HashSet = ignore_directories + .into_iter() .flat_map(|x| simplified_dirs.iter().map(move |d| d.join(&x))) .collect();