diff options
author | Lyndon Brown <jnqnfe@gmail.com> | 2020-05-02 18:18:49 +0100 |
---|---|---|
committer | Lyndon Brown <jnqnfe@gmail.com> | 2020-05-02 18:18:49 +0100 |
commit | 22d8ac15dbc75af2acf02447cf045791b137d7d4 (patch) | |
tree | b86b7f8594da58b7b336d97c1d382ce831994df6 | |
parent | 55e17b1e256a4295c67f44e633adaa07f850d4fb (diff) | |
download | vyos-live-build-22d8ac15dbc75af2acf02447cf045791b137d7d4.tar.gz vyos-live-build-22d8ac15dbc75af2acf02447cf045791b137d7d4.zip |
options: de-duplicate common option handling
-rwxr-xr-x | functions/arguments.sh | 108 | ||||
-rwxr-xr-x | scripts/build/config | 39 |
2 files changed, 59 insertions, 88 deletions
diff --git a/functions/arguments.sh b/functions/arguments.sh index c40bab4ca..a17cf3c1e 100755 --- a/functions/arguments.sh +++ b/functions/arguments.sh @@ -28,60 +28,11 @@ Arguments () while true do case "${1}" in - --breakpoints) - _BREAKPOINTS="true" + --breakpoints|--color|--debug|--force|-h|--help|--no-color|--quiet|-u|--usage|--verbose|-v|--version) + Handle_common_option "${1}" shift ;; - --color) - _COLOR="true" - _COLOR_OUT="true" - _COLOR_ERR="true" - shift - ;; - - --no-color) - _COLOR="false" - _COLOR_OUT="false" - _COLOR_ERR="false" - shift - ;; - - --debug) - _DEBUG="true" - shift - ;; - - --force) - _FORCE="true" - shift - ;; - - -h|--help) - Man - shift - ;; - - --quiet) - _QUIET="true" - shift - ;; - - -u|--usage) - Usage --exit - shift - ;; - - --verbose) - _VERBOSE="true" - shift - ;; - - -v|--version) - echo "${VERSION}" - exit 0 - ;; - --) shift break @@ -94,3 +45,58 @@ Arguments () esac done } + +Handle_common_option () +{ + case "${1}" in + --breakpoints) + _BREAKPOINTS="true" + ;; + + --color) + _COLOR="true" + _COLOR_OUT="true" + _COLOR_ERR="true" + ;; + + --no-color) + _COLOR="false" + _COLOR_OUT="false" + _COLOR_ERR="false" + ;; + + --debug) + _DEBUG="true" + ;; + + --force) + _FORCE="true" + ;; + + -h|--help) + Man + ;; + + --quiet) + _QUIET="true" + ;; + + -u|--usage) + Usage --exit + ;; + + --verbose) + _VERBOSE="true" + ;; + + -v|--version) + echo "${VERSION}" + exit 0 + ;; + + *) + Echo_error "Internal error: Unknown common option '%s'" "${1}" + exit 1 + ;; + esac +} diff --git a/scripts/build/config b/scripts/build/config index 7f19aaeb2..426838f9f 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -256,8 +256,8 @@ Local_arguments () # General options - --breakpoints) - _BREAKPOINTS="true" + --breakpoints|--debug|--force|-h|--help|--quiet|-u|--usage|--verbose|-v|--version) + Handle_common_option "${1}" shift ;; @@ -266,46 +266,11 @@ Local_arguments () shift ;; - --debug) - _DEBUG="true" - shift - ;; - - --force) - _FORCE="true" - shift - ;; - - -h|--help) - Man - shift - ;; - --no-color) _COLOR="false" shift ;; - --quiet) - _QUIET="true" - shift - ;; - - -u|--usage) - Usage --exit - shift - ;; - - --verbose) - _VERBOSE="true" - shift - ;; - - -v|--version) - echo "${VERSION}" - exit 0 - ;; - # Build config options --apt) |