Skip to content

Commit

Permalink
flags: -h: Support showing help for multiple specified flags at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Akianonymus committed Jul 14, 2022
1 parent d8a7110 commit 60598de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
21 changes: 12 additions & 9 deletions release/bash/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ _parser_setup_flag_help \
"Print help for all flags and basic usage instructions.
To see help for a specific flag, --help flag_name ( with or without dashes )
e.g: ${0##*/} --help aria"
Can also specify multiple flag names
e.g: ${0##*/} --help config list-accounts"
_parser_setup_flag_preprocess 4<<'EOF'
###################################################
# 1st arg - can be flag name
Expand All @@ -714,14 +715,16 @@ _parser_setup_flag_preprocess 4<<'EOF'
###################################################
_usage() {
[ -n "${1}" ] && {
help_usage_usage=""
_flag_help "${1}" help_usage_usage
for flag_usage in "${@}"; do
help_usage_usage=""
_flag_help "${flag_usage}" help_usage_usage
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${1}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${flag_usage}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
done
exit 0
}
Expand All @@ -730,7 +733,7 @@ _usage() {
}
EOF
_parser_setup_flag_process 4<<'EOF'
_usage "${2}"
shift 1 && _usage "${@}"
EOF
[ "${GUPLOAD_INSTALLED_WITH:-}" = script ]&&{
_parser_setup_flag "-u --update" 0
Expand Down
21 changes: 12 additions & 9 deletions release/sh/gupload
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ _parser_setup_flag_help \
"Print help for all flags and basic usage instructions.
To see help for a specific flag, --help flag_name ( with or without dashes )
e.g: ${0##*/} --help aria"
Can also specify multiple flag names
e.g: ${0##*/} --help config list-accounts"
_parser_setup_flag_preprocess 4<<'EOF'
###################################################
# 1st arg - can be flag name
Expand All @@ -687,14 +688,16 @@ _parser_setup_flag_preprocess 4<<'EOF'
###################################################
_usage() {
[ -n "${1}" ] && {
help_usage_usage=""
_flag_help "${1}" help_usage_usage
for flag_usage in "${@}"; do
help_usage_usage=""
_flag_help "${flag_usage}" help_usage_usage
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${1}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${flag_usage}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
done
exit 0
}
Expand All @@ -703,7 +706,7 @@ _usage() {
}
EOF
_parser_setup_flag_process 4<<'EOF'
_usage "${2}"
shift 1 && _usage "${@}"
EOF
[ "${GUPLOAD_INSTALLED_WITH:-}" = script ]&&{
_parser_setup_flag "-u --update" 0
Expand Down
23 changes: 13 additions & 10 deletions src/common/upload-flags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ EOF
"Print help for all flags and basic usage instructions.
To see help for a specific flag, --help flag_name ( with or without dashes )
e.g: ${0##*/} --help aria"
Can also specify multiple flag names
e.g: ${0##*/} --help config list-accounts"

_parser_setup_flag_preprocess 4<< 'EOF'
###################################################
Expand All @@ -576,14 +577,16 @@ To see help for a specific flag, --help flag_name ( with or without dashes )
###################################################
_usage() {
[ -n "${1}" ] && {
help_usage_usage=""
_flag_help "${1}" help_usage_usage
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${1}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
for flag_usage in "${@}"; do
help_usage_usage=""
_flag_help "${flag_usage}" help_usage_usage
if [ -z "${help_usage_usage}" ]; then
printf "%s\n" "Error: No help found for ${flag_usage}"
else
printf "%s\n%s\n%s\n" "${__PARSER_BAR}" "${help_usage_usage}" "${__PARSER_BAR}"
fi
done
exit 0
}
Expand All @@ -593,7 +596,7 @@ _usage() {
EOF

_parser_setup_flag_process 4<< 'EOF'
_usage "${2}"
shift 1 && _usage "${@}"
EOF
###################################################

Expand Down

0 comments on commit 60598de

Please sign in to comment.