Skip to content

Commit

Permalink
Fix reading of main parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bootandy committed Dec 11, 2023
1 parent 23da246 commit 7584de8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 59 deletions.
19 changes: 7 additions & 12 deletions completions/_dust
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand All @@ -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]' \
Expand All @@ -71,7 +66,7 @@ _dust() {
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::inputs:' \
'*::params:' \
&& ret=0
}

Expand Down
4 changes: 2 additions & 2 deletions completions/_dust.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion completions/dust.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 <inputs>..."
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
Expand Down
10 changes: 5 additions & 5 deletions man-page/dust.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -87,7 +87,7 @@ Print help
\fB\-V\fR, \fB\-\-version\fR
Print version
.TP
[\fIinputs\fR]
[\fIparams\fR]

.SH VERSION
v0.8.6
12 changes: 7 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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$\" "),
Expand All @@ -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$\" "),
)
Expand Down Expand Up @@ -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)))
}
33 changes: 10 additions & 23 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -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() {
Expand All @@ -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]
Expand Down Expand Up @@ -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<usize> = m.get_many("ports")
.expect("`port`is required")
.copied()
.collect();
assert_eq!(vals, [22, 80, 2020]);
}
}
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>("params") {
Some(values) => values.map(|v| v.as_str()).collect::<Vec<&str>>(),
None => vec!["."],
};

Expand All @@ -112,17 +112,17 @@ 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::<usize>("width") {
let terminal_width: usize = match options.get_one::<usize>("width") {
Some(&val) => val,
None => get_width_of_terminal()
None => get_width_of_terminal(),
};

let depth = config.get_depth(&options);

// 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::<usize>("number_of_lines"){
let number_of_lines = match options.get_one::<usize>("number_of_lines") {
Some(&val) => val,
None => {
if depth != usize::MAX {
Expand All @@ -135,15 +135,14 @@ fn main() {

let no_colors = init_color(config.get_no_colors(&options));

// let ix : Option<ValuesRef<Vec<String>>> = options.get_many("ignore_directory");

let ix2: Vec<&str> = match options.get_many("ignore_directory") {
Some(values) => values.copied().collect::<Vec<&str>>(),
let ignore_directories = match options.get_many::<String>("ignore_directory") {
Some(values) => values
.map(|v| v.as_str())
.map(PathBuf::from)
.collect::<Vec<PathBuf>>(),
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");
Expand All @@ -154,6 +153,7 @@ fn main() {
.unwrap_or_default();

let ignored_full_path: HashSet<PathBuf> = ignore_directories
.into_iter()
.flat_map(|x| simplified_dirs.iter().map(move |d| d.join(&x)))
.collect();

Expand Down

0 comments on commit 7584de8

Please sign in to comment.