Redo 'Fix zsh completion' with clap

Because I'm not familiar with Rust, when I was working on
https://github.com/bootandy/dust/pull/390 I didn't realize that the
completions were auto-generated via clap. I'm sorry. This redoes it
with clap.

This improves not only the completions but also the --help and the
man page. Also the --output-format flag will raise an error if the
given value is invalid.
This commit is contained in:
Taro Tanaka
2024-04-28 17:06:10 +09:00
committed by andy.boot
parent 87581f328e
commit e2fe656296
7 changed files with 106 additions and 66 deletions
+21 -36
View File
@@ -15,26 +15,26 @@ _dust() {
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'-d+[Depth to show]:depth' \
'--depth=[Depth to show]:depth' \
'-n+[Number of lines of output to show. (Default is terminal_height - 10)]:number of lines' \
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]:number of lines' \
'*-X+[Exclude any file or directory with this name]:ignore directory:_files' \
'*--ignore-directory=[Exclude any file or directory with this name]:ignore directory:_files' \
'-I+[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:ignore all in file:_files' \
'--ignore-all-in-file=[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:ignore all in file:_files' \
'-z+[Minimum size file to include in output]:min size' \
'--min-size=[Minimum size file to include in output]:min size' \
'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]:invert filter' \
'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]:invert filter' \
'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:filter' \
'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:filter' \
'-w+[Specify width of output overriding the auto detection of terminal width]:width' \
'--terminal_width=[Specify width of output overriding the auto detection of terminal width]:width' \
'-o+[Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size]:output format:_dust_output_formats' \
'--output-format=[Changes output display size. si will print sizes in powers of 1000. b/bytes kb kib mb mib gb gib will print the whole tree in that size]:output format:_dust_output_formats' \
'-S+[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:stack size' \
'--stack-size=[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:stack size' \
'-d+[Depth to show]:DEPTH: ' \
'--depth=[Depth to show]:DEPTH: ' \
'-n+[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER: ' \
'--number-of-lines=[Number of lines of output to show. (Default is terminal_height - 10)]:NUMBER: ' \
'*-X+[Exclude any file or directory with this name]:PATH:_files' \
'*--ignore-directory=[Exclude any file or directory with this name]:PATH:_files' \
'-I+[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:FILE:_files' \
'--ignore-all-in-file=[Exclude any file or directory with a regex matching that listed in this file, the file entries will be added to the ignore regexs provided by --invert_filter]:FILE:_files' \
'-z+[Minimum size file to include in output]:MIN_SIZE: ' \
'--min-size=[Minimum size file to include in output]:MIN_SIZE: ' \
'(-e --filter -t --file_types)*-v+[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]:REGEX: ' \
'(-e --filter -t --file_types)*--invert-filter=[Exclude filepaths matching this regex. To ignore png files type\: -v "\\.png\$" ]:REGEX: ' \
'(-t --file_types)*-e+[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:REGEX: ' \
'(-t --file_types)*--filter=[Only include filepaths matching this regex. For png files type\: -e "\\.png\$" ]:REGEX: ' \
'-w+[Specify width of output overriding the auto detection of terminal width]:WIDTH: ' \
'--terminal_width=[Specify width of output overriding the auto detection of terminal width]:WIDTH: ' \
'-o+[Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.]:FORMAT:(si b k m g t kb mb gb tb)' \
'--output-format=[Changes output display size. si will print sizes in powers of 1000. b k m g t kb mb gb tb will print the whole tree in that size.]:FORMAT:(si b k m g t kb mb gb tb)' \
'-S+[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:STACK_SIZE: ' \
'--stack-size=[Specify memory to use as stack size - use if you see\: '\''fatal runtime error\: stack overflow'\'' (default low memory=1048576, high memory=1073741824)]:STACK_SIZE: ' \
'-p[Subdirectories will not have their path shortened]' \
'--full-paths[Subdirectories will not have their path shortened]' \
'-L[dereference sym links - Treat sym links as directories and go into them]' \
@@ -72,7 +72,7 @@ _dust() {
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*: :_files' \
'*::params:_files' \
&& ret=0
}
@@ -82,21 +82,6 @@ _dust_commands() {
_describe -t commands 'dust commands' commands "$@"
}
(( $+functions[_dust_output_formats] )) ||
_dust_output_formats() {
local -a output_formats=(
'si[sizes in powers of 1000]'
'b[bytes]'
'kb[kilobytes]'
'kib[kibibytes]'
'mb[megabytes]'
'mib[mebibytes]'
'gb[gigabytes]'
'gib[gibibytes]'
)
_values 'output format' "${output_formats[@]}"
}
if [ "$funcstack[1]" = "_dust" ]; then
_dust "$@"
else