From 37f4528eea77e3481c36b9c194f1f4c69879b694 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 12 Aug 2022 02:46:52 +0900 Subject: [PATCH] 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. --- include/opt.sh | 4 ++++ 1 file changed, 4 insertions(+) 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 -- 2.47.3