Skip to content

Commit

Permalink
- Remove redundant code in usage function
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Jul 5, 2024
1 parent 9271e70 commit f87986a
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 109 deletions.
3 changes: 3 additions & 0 deletions examples/catch-all/src/root_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo "# this file is located in 'src/root_command.sh'"
echo "# you can edit it freely and regenerate (it will not be overwritten)"
inspect_args
28 changes: 14 additions & 14 deletions examples/completions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ _cli_completions_filter() {

if [[ "${cur:0:1}" == "-" ]]; then
echo "$words"

else
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
Expand All @@ -226,56 +226,56 @@ _cli_completions() {

case "$compline" in
'download'*'--handler')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")
;;

'upload'*'--user')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
;;

'completions'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help -h")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help -h")" -- "$cur")
;;

'd'*'--handler')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")
;;

'upload'*'-u')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
;;

'download'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")
;;

'u'*'--user')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
;;

'upload'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")
;;

'u'*'-u')
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")
;;

'd'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")
;;

'u'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version -h -v completions d download u upload")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version -h -v completions d download u upload")" -- "$cur")
;;

esac
} &&
complete -F _cli_completions cli
complete -F _cli_completions cli

# ex: filetype=sh

Expand Down
28 changes: 14 additions & 14 deletions examples/completions/src/lib/send_completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ send_completions() {
echo $''
echo $' if [[ "${cur:0:1}" == "-" ]]; then'
echo $' echo "$words"'
echo $' '
echo $''
echo $' else'
echo $' for word in $words; do'
echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")'
Expand All @@ -31,56 +31,56 @@ send_completions() {
echo $''
echo $' case "$compline" in'
echo $' \'download\'*\'--handler\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'upload\'*\'--user\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")'
echo $' ;;'
echo $''
echo $' \'completions\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help -h")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help -h")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'d\'*\'--handler\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "curl wget")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'upload\'*\'-u\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")'
echo $' ;;'
echo $''
echo $' \'download\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'u\'*\'--user\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")'
echo $' ;;'
echo $''
echo $' \'upload\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'u\'*\'-u\')'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A user -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A user -- "$cur")'
echo $' ;;'
echo $''
echo $' \'d\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_cli_completions_filter "--force --handler --help -f -h")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'u\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A directory -A user -W "$(_cli_completions_filter "--help --password --user -h -p -u CHANGELOG.md README.md")" -- "$cur")'
echo $' ;;'
echo $''
echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version -h -v completions d download u upload")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version -h -v completions d download u upload")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $'} &&'
echo $'complete -F _cli_completions cli'
echo $' complete -F _cli_completions cli'
echo $''
echo $'# ex: filetype=sh'
}
2 changes: 1 addition & 1 deletion examples/render-mandoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ISSUE TRACKER
AUTHORS
Lana Lang.

Version 0.1.0 April 2024 download(1)
Version 0.1.0 July 2024 download(1)


````
Expand Down
14 changes: 7 additions & 7 deletions examples/render-mandoc/docs/download.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.\" Automatically generated by Pandoc 3.1.9
.\" Automatically generated by Pandoc 3.2
.\"
.TH "download" "1" "April 2024" "Version 0.1.0" "Sample application"
.TH "download" "1" "July 2024" "Version 0.1.0" "Sample application"
.SH NAME
\f[B]download\f[R] - Sample application
\f[B]download\f[R] \- Sample application
.SH SYNOPSIS
\f[B]download\f[R] SOURCE [TARGET...]
OPTIONS
Expand All @@ -20,15 +20,15 @@ Target filename (default: same as source)
.IP \[bu] 2
\f[I]Repeatable\f[R]
.SH OPTIONS
.SS --force, -f
.SS \-\-force, \-f
Overwrite existing files
.SS --debug, -d
.SS \-\-debug, \-d
Show debug information
.SH DEPENDENCIES
.SS aws-cli
.SS aws\-cli
Download from <https://aws.amazon.com/cli/>
.SH SEE ALSO
\f[B]docker\f[R](1), \f[B]docker-compose.yml\f[R](5)
\f[B]docker\f[R](1), \f[B]docker\-compose.yml\f[R](5)
.SH ISSUE TRACKER
Report issues at <https://github.com/lanalang/smallville>
.SH AUTHORS
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% April 2024
% July 2024

NAME
==================================================
Expand Down
23 changes: 9 additions & 14 deletions lib/bashly/views/command/usage.gtx
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
= view_marker

> {{ function_name }}_usage() {
> if [[ -n $long_usage ]]; then

if summary == help
> printf "{{ caption_string.sanitize_for_print }}\n"
> echo
> printf "{{ caption_string.sanitize_for_print }}\n\n"
else
> printf "{{ full_name }}\n"
> echo
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n"
> echo
> if [[ -n $long_usage ]]; then
> printf "{{ full_name }}\n\n"
> printf "{{ help.wrap(78).indent(2).sanitize_for_print }}\n\n"
> else
> printf "{{ caption_string.sanitize_for_print }}\n\n"
> fi
end

> else
> printf "{{ caption_string.sanitize_for_print }}\n"
> echo
> fi
>

if alt&.any?
> printf "{{ strings[:command_alias] % { alias: alt.join(', ') } }}\n"
> echo
Expand Down Expand Up @@ -48,3 +41,5 @@ end
commands.each do |command|
= command.render 'usage'
end


14 changes: 7 additions & 7 deletions spec/approvals/cli/add/comp-function-file
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ send_completions() {
echo $''
echo $' if [[ "${cur:0:1}" == "-" ]]; then'
echo $' echo "$words"'
echo $' '
echo $''
echo $' else'
echo $' for word in $words; do'
echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")'
Expand All @@ -31,28 +31,28 @@ send_completions() {
echo $''
echo $' case "$compline" in'
echo $' \'download\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'upload\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'d\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur")'
echo $' ;;'
echo $''
echo $' \'u\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur")'
echo $' ;;'
echo $''
echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version -h -v d download u upload")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version -h -v d download u upload")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $'} &&'
echo $'complete -F _cli_completions cli'
echo $' complete -F _cli_completions cli'
echo $''
echo $'# ex: filetype=sh'
}
14 changes: 7 additions & 7 deletions spec/approvals/cli/add/comp-script-file
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _cli_completions_filter() {

if [[ "${cur:0:1}" == "-" ]]; then
echo "$words"

else
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
Expand All @@ -29,27 +29,27 @@ _cli_completions() {

case "$compline" in
'download'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur")
;;

'upload'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur")
;;

'd'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur")
;;

'u'*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --password --user -h -p -u")" -- "$cur")
;;

*)
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_cli_completions_filter "--help --version -h -v d download u upload")" -- "$cur" )
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--help --version -h -v d download u upload")" -- "$cur")
;;

esac
} &&
complete -F _cli_completions cli
complete -F _cli_completions cli

# ex: filetype=sh
6 changes: 3 additions & 3 deletions spec/approvals/completions/function
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ custom_name() {
echo $''
echo $' if [[ "${cur:0:1}" == "-" ]]; then'
echo $' echo "$words"'
echo $' '
echo $''
echo $' else'
echo $' for word in $words; do'
echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")'
Expand All @@ -30,12 +30,12 @@ custom_name() {
echo $''
echo $' case "$compline" in'
echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -A file -W "$(_get_completions_filter "--force --help --verbose --version -h -v")" -- "$cur" )'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -A file -W "$(_get_completions_filter "--force --help --verbose --version -h -v")" -- "$cur")'
echo $' ;;'
echo $''
echo $' esac'
echo $'} &&'
echo $'complete -F _get_completions get'
echo $' complete -F _get_completions get'
echo $''
echo $'# ex: filetype=sh'
}
Loading

0 comments on commit f87986a

Please sign in to comment.