concept

CLI configuration precedence

Application-defined priority order. Decide whether empty values are invalid or fallbacks; validate the selected value and treat configuration as data.

Formal Syntax & Structure

bash syntaxbash
CLI > environment > parsed config > default

Return Value

selected value

Application-defined priority order. Decide whether empty values are invalid or fallbacks; validate the selected value and treat configuration as data.

Working Example

Example Snippetbash
resolve() {    local default=dev config mode    config=${BM_CONFIG-$default}    mode=${BM_MODE-$config}    if (( $# )); then        if (( $# != 2 )) || [[ $1 != --mode ]]; then return 2; fi        mode=$2    fi    case $mode in        dev|test|prod) printf '%s\n' "$mode" ;;        *) printf 'invalid mode\n' >&2; return 2 ;;    esac}unset BM_MODE BM_CONFIGresolveBM_CONFIG=testresolveBM_MODE=prod resolveBM_MODE=prod resolve --mode dev
Bash Reference