From: Matthias Kruk Date: Thu, 11 Aug 2022 17:46:52 +0000 (+0900) Subject: include/opt: Show default values in help text X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=37f4528eea77e3481c36b9c194f1f4c69879b694;p=toolbox include/opt: Show default values in help text The opt module does not show the default values of options in the help text, leaving the user guessing what the values of options are if they are not specified on the command line. This commit modifies `opt_print_help()` so that it displays the default values of options that have a value and a default set. --- diff --git a/include/opt.sh b/include/opt.sh index 2fce9c5..d9c596a 100644 --- a/include/opt.sh +++ b/include/opt.sh @@ -156,6 +156,10 @@ opt_print_help() { printf "\t-%s\t--%s\t%s\n" \ "$short" "$long" "$desc" + if (( ${__opt_flags["$long"]} & __opt_flag_has_value )) && + array_contains "$long" "${!__opt_default[@]}"; then + printf '\t\t\t(Default: %s)\n' "${__opt_default[$long]}" + fi done | column -s $'\t' -t return 2