From 2f17f856b3e125677e834f10ae3b0e9be48047e0 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 23 May 2023 16:24:12 +0200 Subject: [PATCH] Fixing scripts/get-module-version --- scripts/functions.rc | 2 +- scripts/get-module-version | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/functions.rc b/scripts/functions.rc index daf6ab2..e4e753f 100644 --- a/scripts/functions.rc +++ b/scripts/functions.rc @@ -8,7 +8,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.3.1" +VERSION="0.3.2" # shellcheck disable=SC2034 STD_SHORT_OPTIONS="sqdvhV" diff --git a/scripts/get-module-version b/scripts/get-module-version index daf9e73..07df467 100755 --- a/scripts/get-module-version +++ b/scripts/get-module-version @@ -20,6 +20,8 @@ PUPPET_ENV='*' DEFAULT_ENV_DIR="/etc/puppetlabs/code/environments" ENV_DIR="${DEFAULT_ENV_DIR}" +detect_color + DESCRIPTION=$( cat <<-EOF Retrieving version number of given Puppet module(s) in all environments. @@ -34,7 +36,7 @@ usage() { ${BASE_NAME} [-V|--version] Mandatory Parameter(s): - MODULE: The short name of the module(s) (without vendor), for which the + MODULE: The short name of the module(s) (without vendor), for which the current used version should be shown. Options: @@ -85,20 +87,20 @@ get_options() { while [[ "$i" -lt "${len}" ]] ; do arg="${REMAINING_OPTS[$i]}" - debug "Evaluating option '${CYAN}${arg}${NORMAL}' ..." + # debug "Evaluating option '${CYAN}${arg}${NORMAL}' ..." case "${arg}" in -E|--env|--environment) j=$(( $i + 1 )) PUPPET_ENV="${REMAINING_OPTS[$j]}" - debug "Puppet environment is now: '${CYAN}${PUPPET_ENV}${NORMAL}', i = $i." i=$(( $i + 2 )) + # debug "Puppet environment is now: '${CYAN}${PUPPET_ENV}${NORMAL}', i = $i." ;; -D|--dir) j=$(( $i + 1 )) ENV_DIR="${REMAINING_OPTS[$j]}" - debug "Puppet environment directory is now: '${CYAN}${ENV_DIR}${NORMAL}', i = $i." i=$(( $i + 2 )) + # debug "Puppet environment directory is now: '${CYAN}${ENV_DIR}${NORMAL}', i = $i." ;; *) echo -e "Internal error - option '${RED}${arg}${NORMAL}' was wrong!" exit 1 @@ -106,13 +108,6 @@ get_options() { esac done - if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then - error "Unknown options: ${REMAINING_OPTS[*]}" - echo >&2 - usage >&2 - exit 2 - fi - if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then error "No module name to search for the version given." echo >&2 @@ -122,6 +117,8 @@ get_options() { if [[ ! -d "${ENV_DIR}" ]] ; then error "Puppet environments directory '${RED}${ENV_DIR}${NORMAL}' does not exists." + echo >&2 + usage >&2 exit 5 fi -- 2.39.5