diff --git a/bin/postmanCli b/bin/postmanCli index b110b402..7a230b29 100755 --- a/bin/postmanCli +++ b/bin/postmanCli @@ -1,13 +1,12 @@ #!/usr/bin/env bash ############################################################################### -# GENERATED FACADE FROM https://github.com/fchastanet/bash-tools/tree/master/src/_binaries/Postman/postmanCli.sh +# GENERATED FROM https://github.com/fchastanet/bash-tools-framework/tree/master/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml # DO NOT EDIT IT # @generated ############################################################################### # shellcheck disable=SC2288,SC2034 -# BIN_FILE=${BASH_TOOLS_ROOT_DIR}/bin/postmanCli -# VAR_RELATIVE_FRAMEWORK_DIR_TO_CURRENT_DIR=.. -# FACADE + + # ensure that no user aliases could interfere with # commands used in this script @@ -62,13 +61,6 @@ interruptManagement() { kill -s INT "$$" } trap interruptManagement INT -SCRIPT_NAME=${0##*/} -REAL_SCRIPT_FILE="$(readlink -e "$(realpath "${BASH_SOURCE[0]}")")" -if [[ -n "${EMBED_CURRENT_DIR}" ]]; then - CURRENT_DIR="${EMBED_CURRENT_DIR}" -else - CURRENT_DIR="${REAL_SCRIPT_FILE%/*}" -fi ################################################ # Temp dir management @@ -102,6 +94,20 @@ cleanOnExit() { } trap cleanOnExit EXIT HUP QUIT ABRT TERM + +SCRIPT_NAME=${0##*/} +REAL_SCRIPT_FILE="$(readlink -e "$(realpath "${BASH_SOURCE[0]}")")" +if [[ -n "${EMBED_CURRENT_DIR}" ]]; then + CURRENT_DIR="${EMBED_CURRENT_DIR}" +else + CURRENT_DIR="${REAL_SCRIPT_FILE%/*}" +fi +FRAMEWORK_ROOT_DIR="$(cd "${CURRENT_DIR}/.." && pwd -P)" +FRAMEWORK_SRC_DIR="${FRAMEWORK_ROOT_DIR}/src" +FRAMEWORK_BIN_DIR="${FRAMEWORK_ROOT_DIR}/bin" +FRAMEWORK_VENDOR_DIR="${FRAMEWORK_ROOT_DIR}/vendor" +FRAMEWORK_VENDOR_BIN_DIR="${FRAMEWORK_ROOT_DIR}/vendor/bin" + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -132,310 +138,86 @@ export __VERBOSE_LEVEL_DEBUG=2 # @description verbose level info export __VERBOSE_LEVEL_TRACE=3 -# @description Display message using info color (bg light blue/fg white) -# @arg $1 message:String the message to display -# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs -# @env LOG_CONTEXT String allows to contextualize the log -Log::displayInfo() { - local type="${2:-INFO}" - if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_INFO)); then - Log::computeDuration - echo -e "${__INFO_COLOR}${type} - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 - fi - Log::logInfo "$1" "${type}" -} - -# @description Display message using debug color (gray) -# @arg $1 message:String the message to display -# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs -# @env LOG_CONTEXT String allows to contextualize the log -Log::displayDebug() { - if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_DEBUG)); then - Log::computeDuration - echo -e "${__DEBUG_COLOR}DEBUG - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 - fi - Log::logDebug "$1" -} -# @description Display message using warning color (yellow) -# @arg $1 message:String the message to display -# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs -# @env LOG_CONTEXT String allows to contextualize the log -Log::displayWarning() { - if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_WARNING)); then - Log::computeDuration - echo -e "${__WARNING_COLOR}WARN - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 - fi - Log::logWarning "$1" +# @description check if an element is contained in an array +# +# @arg $1 needle:String +# @arg $@ array:String[] +# @exitcode 0 if found +# @exitcode 1 otherwise +# @example +# Array::contains "${libPath}" "${__BASH_FRAMEWORK_IMPORTED_FILES[@]}" +Array::contains() { + local element + for element in "${@:2}"; do + [[ "${element}" = "$1" ]] && return 0 + done + return 1 } -# @description Display message using error color (red) -# @arg $1 message:String the message to display -# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs -# @env LOG_CONTEXT String allows to contextualize the log -Log::displayError() { - if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_ERROR)); then - Log::computeDuration - echo -e "${__ERROR_COLOR}ERROR - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 - fi - Log::logError "$1" -} -# @description load colors theme constants -# @warning if tty not opened, noColor theme will be chosen -# @arg $1 theme:String the theme to use (default, noColor) -# @arg $@ args:String[] -# @set __ERROR_COLOR String indicate error status -# @set __INFO_COLOR String indicate info status -# @set __SUCCESS_COLOR String indicate success status -# @set __WARNING_COLOR String indicate warning status -# @set __SKIPPED_COLOR String indicate skipped status -# @set __DEBUG_COLOR String indicate debug status -# @set __HELP_COLOR String indicate help status -# @set __TEST_COLOR String not used -# @set __TEST_ERROR_COLOR String not used -# @set __HELP_TITLE_COLOR String used to display help title in help strings -# @set __HELP_OPTION_COLOR String used to display highlight options in help strings -# -# @set __RESET_COLOR String reset default color +# @description concatenate each element of an array with a separator +# but wrapping text when line length is more than provided argument +# The algorithm will try not to cut the array element if it can. +# - if an arg can be placed on current line it will be, +# otherwise current line is printed and arg is added to the new +# current line +# - Empty arg is interpreted as a new line. +# - Add \r to arg in order to force break line and avoid following +# arg to be concatenated with current arg. # -# @set __HELP_EXAMPLE String to remove -# @set __HELP_TITLE String to remove -# @set __HELP_NORMAL String to remove -# shellcheck disable=SC2034 -UI::theme() { - local theme="${1-default}" - if [[ ! "${theme}" =~ -force$ ]] && ! Assert::tty; then - theme="noColor" +# @arg $1 glue:String +# @arg $2 maxLineLength:int +# @arg $3 indentNextLine:int +# @arg $@ array:String[] +Array::wrap2() { + local glue="${1-}" + local -i glueLength="${#glue}" + shift || true + local -i maxLineLength=$1 + shift || true + local -i indentNextLine=$1 + shift || true + local indentStr="" + if ((indentNextLine > 0)); then + indentStr="$(head -c "${indentNextLine}" &2 - Log::logFatal "$1" - exit 1 -} + ( + local currentLine + local -i currentLineLength=0 isNewline=1 argLength=0 + local -a additionalLines + local -i previousLineEmpty=0 + local arg="" -# @description create a temp file using default TMPDIR variable -# initialized in _includes/_commonHeader.sh -# @env TMPDIR String (default value /tmp) -# @arg $1 templateName:String template name to use(optional) -Framework::createTempFile() { - mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" -} - -# @description ensure env files are loaded -# @arg $@ list of default files to load at the end -# @exitcode 1 if one of env files fails to load -# @stderr diagnostics information is displayed -# shellcheck disable=SC2120 -Env::requireLoad() { - local -a defaultFiles=("$@") - # get list of possible config files - local -a configFiles=() - if [[ -n "${BASH_FRAMEWORK_ENV_FILES[0]+1}" ]]; then - # BASH_FRAMEWORK_ENV_FILES is an array - configFiles+=("${BASH_FRAMEWORK_ENV_FILES[@]}") - fi - local localFrameworkConfigFile - localFrameworkConfigFile="$(pwd)/.framework-config" - if [[ -f "${localFrameworkConfigFile}" ]]; then - configFiles+=("${localFrameworkConfigFile}") - fi - if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then - configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") - fi - configFiles+=("${optionEnvFiles[@]}") - configFiles+=("${defaultFiles[@]}") - - for file in "${configFiles[@]}"; do - # shellcheck source=/.framework-config - CURRENT_LOADED_ENV_FILE="${file}" source "${file}" || { - Log::displayError "while loading config file: ${file}" - return 1 - } - done -} - -# @description activate or not Log::display* and Log::log* functions -# based on BASH_FRAMEWORK_DISPLAY_LEVEL and BASH_FRAMEWORK_LOG_LEVEL -# environment variables loaded by Env::requireLoad -# try to create log file and rotate it if necessary -# @noargs -# @set BASH_FRAMEWORK_LOG_LEVEL int to OFF level if BASH_FRAMEWORK_LOG_FILE is empty or not writable -# @env BASH_FRAMEWORK_DISPLAY_LEVEL int -# @env BASH_FRAMEWORK_LOG_LEVEL int -# @env BASH_FRAMEWORK_LOG_FILE String -# @env BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION int do log rotation if > 0 -# @exitcode 0 always successful -# @stderr diagnostics information about log file is displayed -# @require Env::requireLoad -# @require UI::requireTheme -Log::requireLoad() { - if [[ -z "${BASH_FRAMEWORK_LOG_FILE:-}" ]]; then - BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} - export BASH_FRAMEWORK_LOG_LEVEL - fi - - if ((BASH_FRAMEWORK_LOG_LEVEL > __LEVEL_OFF)); then - if [[ ! -f "${BASH_FRAMEWORK_LOG_FILE}" ]]; then - if [[ ! -d "${BASH_FRAMEWORK_LOG_FILE%/*}" ]]; then - if ! mkdir -p "${BASH_FRAMEWORK_LOG_FILE%/*}" 2>/dev/null; then - BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} - echo -e "${__ERROR_COLOR}ERROR - directory ${BASH_FRAMEWORK_LOG_FILE%/*} is not writable${__RESET_COLOR}" >&2 - fi - elif ! touch --no-create "${BASH_FRAMEWORK_LOG_FILE}" 2>/dev/null; then - BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} - echo -e "${__ERROR_COLOR}ERROR - File ${BASH_FRAMEWORK_LOG_FILE} is not writable${__RESET_COLOR}" >&2 - fi - elif [[ ! -w "${BASH_FRAMEWORK_LOG_FILE}" ]]; then - BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} - echo -e "${__ERROR_COLOR}ERROR - File ${BASH_FRAMEWORK_LOG_FILE} is not writable${__RESET_COLOR}" >&2 - fi - fi - - if ((BASH_FRAMEWORK_LOG_LEVEL > __LEVEL_OFF)); then - # will always be created even if not in info level - Log::logMessage "INFO" "Logging to file ${BASH_FRAMEWORK_LOG_FILE} - Log level ${BASH_FRAMEWORK_LOG_LEVEL}" - if ((BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION > 0)); then - Log::rotate "${BASH_FRAMEWORK_LOG_FILE}" "${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION}" - fi - fi -} - -# @description concatenate each element of an array with a separator -# but wrapping text when line length is more than provided argument -# The algorithm will try not to cut the array element if it can. -# - if an arg can be placed on current line it will be, -# otherwise current line is printed and arg is added to the new -# current line -# - Empty arg is interpreted as a new line. -# - Add \r to arg in order to force break line and avoid following -# arg to be concatenated with current arg. -# -# @arg $1 glue:String -# @arg $2 maxLineLength:int -# @arg $3 indentNextLine:int -# @arg $@ array:String[] -Array::wrap2() { - local glue="${1-}" - local -i glueLength="${#glue}" - shift || true - local -i maxLineLength=$1 - shift || true - local -i indentNextLine=$1 - shift || true - local indentStr="" - if ((indentNextLine > 0)); then - indentStr="$(head -c "${indentNextLine}" 0)); do - arg="$1" - shift || true + while (($# > 0)); do + arg="$1" + shift || true # replace tab by 2 spaces arg="${arg//$'\t'/ }" @@ -502,284 +284,153 @@ Array::wrap2() { ) | sed -E -e 's/[[:blank:]]+$//' } -# @description validates the model file and checks for file existence -# @arg $1 optionModelFile:String the model file to validate -# @arg $2 mode:Enum(pull|push|config) eg: pull/config don't check for file existence -# @exitcode 1 if file optionModelFile does not exists or invalid -# @stderr diagnostics information is displayed -Postman::Model::validate() { - local modelFile="$1" - local mode="$2" - if ! Array::contains "${mode}" pull push config; then - Log::displayError "invalid mode ${mode}" +# @description check if command specified exists or return 1 +# with error and message if not +# +# @arg $1 commandName:String on which existence must be checked +# @arg $2 helpIfNotExists:String a help command to display if the command does not exist +# +# @exitcode 1 if the command specified does not exist +# @stderr diagnostic information + help if second argument is provided +Assert::commandExists() { + local commandName="$1" + local helpIfNotExists="$2" + + "${BASH_FRAMEWORK_COMMAND:-command}" -v "${commandName}" >/dev/null 2>/dev/null || { + Log::displayError "${commandName} is not installed, please install it" + if [[ -n "${helpIfNotExists}" ]]; then + Log::displayInfo "${helpIfNotExists}" + fi return 1 - fi + } + return 0 +} - # shellcheck disable=SC2154 - if [[ ! -f "${modelFile}" ]]; then - Log::displayError "File ${modelFile} does not exist" - return 1 - fi - if ! jq -cre . &>/dev/null <"${modelFile}"; then - Log::displayError "File '${modelFile}' is not a valid json file" +# @description check if tty (interactive mode) is active +# @noargs +# @exitcode 1 if tty not active +# @env NON_INTERACTIVE if 1 consider as not interactive even if environment is interactive +# @env INTERACTIVE if 1 consider as interactive even if environment is not interactive +Assert::tty() { + if [[ "${NON_INTERACTIVE:-0}" = "1" ]]; then return 1 fi - local -i errorCount=0 - - # check name key presence - local name - name="$(jq -cre .name 2>/dev/null <"${modelFile}")" || { - Log::displayError "File '${modelFile}' - missing name property" - ((++errorCount)) - } - if [[ -z "${name}" ]]; then - Log::displayError "File '${modelFile}' name property cannot be empty" - ((++errorCount)) - fi - - # check collections key presence - local expr='.collections | if type=="object" then "yes" else "no" end' - if [[ "$(jq -cre "${expr}" <"${modelFile}")" = "no" ]]; then - Log::displayError "File '${modelFile}' - collections property is missing or is not an object" - ((++errorCount)) - else - local collectionJson - local -i index=0 - # shellcheck disable=SC2030 - jq -cre '.collections | to_entries | map(.value + {key: .key}) | .[]' "${modelFile}" | while IFS=$'\n' read -r collectionJson; do - local collectionFile collectionKey - local status=0 - collectionFile="$(jq -cre .file 2>/dev/null <<<"${collectionJson}")" || status=1 - if [[ "${status}" = 0 ]]; then - collectionKey="$(jq -cre .key 2>/dev/null <<<"${collectionJson}")" || status=1 - else - collectionKey="${index}" - fi - if [[ "${status}" = 1 ]]; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - missing file property" - ((++errorCount)) - else - local configDirectory - configDirectory="$(Postman::Model::getRelativeConfigDirectory "${modelFile}")" - collectionFile="${configDirectory}/${collectionFile}" - case "${mode}" in - push) - if [[ ! -f "${collectionFile}" ]]; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} does not exists" - ((++errorCount)) - continue - fi - if [[ ! -r "${collectionFile}" ]]; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not readable" - ((++errorCount)) - continue - fi - if ! jq -cre . &>/dev/null <"${collectionFile}"; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not a valid json file" - ((++errorCount)) - continue - fi - if ! jq -cre .info.name &>/dev/null <"${collectionFile}"; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} does not seem to be a valid collection file" - ((++errorCount)) - continue - fi - ;; - - pull) - if [[ -f "${collectionFile}" && ! -w "${collectionFile}" ]]; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not writable" - ((++errorCount)) - continue - fi - if [[ ! -f "${collectionFile}" && ! -w "${configDirectory}" ]]; then - Log::displayError "File '${modelFile}' - collection ${collectionKey} - config directory ${configDirectory} is not writable" - ((++errorCount)) - continue - fi - ;; - *) ;; - # ignore - esac - fi - # TODO environment - ((++index)) - done + if [[ "${INTERACTIVE:-0}" = "1" ]]; then + return 0 fi - - # shellcheck disable=SC2031 - ((errorCount == 0)) + tty -s } -# @description validate arguments before calling Postman::Commands::pullCollections -# @arg $1 modelFile:String model file containing the collections to be pulled -# @arg $@ list of collection references to pull (all if not provided) -# @stderr diagnostic logs -# @exitcode * if one of sub commands fails -Postman::Commands::pullCommand() { - local modelFile="$1" - shift || true - - Postman::Model::validate "${modelFile}" "pull" || return 1 - local -a refs - # shellcheck disable=SC2154 - Postman::Model::getCollectionRefs "${modelFile}" refs || return 1 - if (($# > 0)); then - # shellcheck disable=SC2154 - Postman::Model::checkIfValidCollectionRefs "${modelFile}" refs "$@" || return 1 - refs=("$@") - fi +# @description ignore exit code 141 from simple command pipes +# @example use with: +# local resultingStatus=0 +# local -a originalPipeStatus=() +# cmd1 | cmd2 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true +# [[ "${resultingStatus}" = "0" ]] +# @arg $1 resultingStatusCode:&int (passed by reference) (optional) resulting status code +# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array +# @env PIPESTATUS assuming that this function is called like in the example provided +# @see https://unix.stackexchange.com/a/709880/582856 +Bash::handlePipelineFailure() { + local -a pipeStatusBackup=("${PIPESTATUS[@]}") + local -n handlePipelineFailure_resultingStatusCode=$1 + local -n handlePipelineFailure_originalStatus=$2 + # shellcheck disable=SC2034 + handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}") + handlePipelineFailure_resultingStatusCode=0 + local statusCode + for statusCode in "${pipeStatusBackup[@]}"; do + if ((statusCode == 141)); then + return 0 + elif ((statusCode > 0)); then + # shellcheck disable=SC2034 + handlePipelineFailure_resultingStatusCode="${statusCode}" + break + fi + done + return "${handlePipelineFailure_resultingStatusCode}" +} - if ((${#refs} == 0)); then - Log::displayError "No collection refs to pull" - return 1 - else - Log::displayDebug "Collection refs to pull ${refs[*]}" - Postman::Commands::pullCollections "${modelFile}" "${refs[@]}" || return 1 + +# @description check if all requirements are satisfied +# to execute dbImport commands +Db::checkRequirements() { + if [[ "${SKIP_REQUIREMENTS_CHECKS:-0}" = "1" ]]; then + return 0 fi + local -i failures=0 + echo + Assert::commandExists mysql "sudo apt-get install -y mysql-client" || ((++failures)) + Assert::commandExists mysqlshow "sudo apt-get install -y mysql-client" || ((++failures)) + Assert::commandExists mysqldump "sudo apt-get install -y mysql-client" || ((++failures)) + Assert::commandExists pv "sudo apt-get install -y pv" || ((++failures)) + Assert::commandExists gawk "sudo apt-get install -y gawk" || ((++failures)) + Assert::commandExists awk "sudo apt-get install -y gawk" || ((++failures)) + Version::checkMinimal "gawk" "--version" "5.0.1" || ((++failures)) + return "${failures}" } -# @description validate arguments before calling Postman::Commands::pushCollections -# @arg $1 modelFile:String model file containing the collections to be pushed -# @arg $@ list of collection references to push (all if not provided) -# @stderr diagnostic logs -# @exitcode * if one of sub commands fails -Postman::Commands::pushCommand() { - local modelFile="$1" - shift || true - Postman::Model::validate "${modelFile}" "push" || return 1 +# @description ensure env files are loaded +# @arg $@ list of default files to load at the end +# @exitcode 1 if one of env files fails to load +# @stderr diagnostics information is displayed +# shellcheck disable=SC2120 +Env::requireLoad() { + export REQUIRE_FUNCTION_ENV_REQUIRE_LOAD_LOADED=1 - local -a refs - # shellcheck disable=SC2154 - Postman::Model::getCollectionRefs "${modelFile}" refs || return 1 - if (($# > 0)); then - # shellcheck disable=SC2154 - Postman::Model::checkIfValidCollectionRefs "${modelFile}" refs "$@" || return 1 - refs=("$@") + local -a defaultFiles=("$@") + # get list of possible config files + local -a configFiles=() + if [[ -n "${BASH_FRAMEWORK_ENV_FILES[0]+1}" ]]; then + # BASH_FRAMEWORK_ENV_FILES is an array + configFiles+=("${BASH_FRAMEWORK_ENV_FILES[@]}") fi - - if ((${#refs} == 0)); then - Log::displayError "No collection refs to push" - return 1 - else - Log::displayDebug "Collection refs to push ${refs[*]}" - Postman::Commands::pushCollections "${modelFile}" "${refs[@]}" || return 1 + local localFrameworkConfigFile + localFrameworkConfigFile="$(pwd)/.framework-config" + if [[ -f "${localFrameworkConfigFile}" ]]; then + configFiles+=("${localFrameworkConfigFile}") + fi + if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then + configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi + configFiles+=("${optionEnvFiles[@]}") + configFiles+=("${defaultFiles[@]}") + + for file in "${configFiles[@]}"; do + # shellcheck source=/.framework-config + CURRENT_LOADED_ENV_FILE="${file}" source "${file}" || { + Log::displayError "while loading config file: ${file}" + return 1 + } + done } -bashToolsDefaultConfigTemplate="${bashToolsDefaultConfigTemplate:-$( - cat <<'EOF' -# shellcheck disable=SC2034 -# Default settings -# you can override these settings by creating ${HOME}/.bash-tools/.env file - -### -### DISPLAY Level -### minimum level of the messages that will be displayed on screen -### -### 0: NO LOG -### 1: ERROR -### 2: WARNING -### 3: INFO -### 4: DEBUG -### -BASH_FRAMEWORK_DISPLAY_LEVEL=${BASH_FRAMEWORK_DISPLAY_LEVEL:-3} - -### -### DISPLAY duration -### 0: no duration is displayed on the messages -### 1: duration between previous message and current is displayed -### with the message -### -DISPLAY_DURATION=${DISPLAY_DURATION:0} - -### -### Log to file -### -### all log messages will be redirected to log file specified -### this same path will be used inside and outside of the container -### -BASH_FRAMEWORK_LOG_FILE=${BASH_FRAMEWORK_LOG_FILE:-${FRAMEWORK_ROOT_DIR}/logs/bash.log} - -### -### LOG Level -### minimum level of the messages that will be logged into LOG_FILE -### -### 0: NO LOG -### 1: ERROR -### 2: WARNING -### 3: INFO -### 4: DEBUG -### -BASH_FRAMEWORK_LOG_LEVEL=${BASH_FRAMEWORK_LOG_LEVEL:-0} - -# absolute directory containing db import sql dumps -DB_IMPORT_DUMP_DIR=${DB_IMPORT_DUMP_DIR:-${HOME}/.bash-tools/dbImportDumps} - -# garbage collect all files for which modification is greater than eg: 30 days (+30) -# each time an existing file is used by dbImport/dbImportTable -# the file modification time is set to now -DB_IMPORT_GARBAGE_COLLECT_DAYS=${DB_IMPORT_GARBAGE_COLLECT_DAYS:-+30} - -# absolute directory containing dbScripts used by dbScriptAllDatabases -SCRIPTS_FOLDER=${SCRIPTS_FOLDER:-${HOME}/.bash-tools/conf/dbScripts} - -# ----------------------------------------------------- -# AWS Parameters -# ----------------------------------------------------- -S3_BASE_URL=${S3_BASE_URL:-} - -# ----------------------------------------------------- -# Postman Parameters -# ----------------------------------------------------- -POSTMAN_API_KEY= -EOF -)}" - -# @description loads ~/.bash-tools/.env if available -# if not creates it from a default template -# else check if new options need to be added -BashTools::Conf::requireLoad() { - local envFile="${HOME}/.bash-tools/.env" - if [[ ! -f "${envFile}" ]]; then - mkdir -p "${HOME}/.bash-tools" - ( - echo "#!/usr/bin/env bash" - echo "${bashToolsDefaultConfigTemplate}" - ) >"${envFile}" - Log::displayInfo "Configuration file '${envFile}' created" - else - if ! grep -q '^POSTMAN_API_KEY=' "${envFile}"; then - ( - echo '# -----------------------------------------------------' - echo '# Postman Parameters' - echo '# -----------------------------------------------------' - echo 'POSTMAN_API_KEY=' - ) >>"${envFile}" - fi - fi - # shellcheck source=/conf/.env - source "${envFile}" || { - Log::displayError "impossible to load '${envFile}'" - exit 1 - } +# @description print the resolved path relative to DIR +# do not check for path existence +# @arg $1 srcFile:String the file to resolve +# @arg $2 relativeTo:String the directory +# @stdout the resolved path relative to DIR +File::relativeToDir() { + local srcFile="$1" + local relativeTo="$2" + + realpath -m --relative-to="${relativeTo}" "${srcFile}" } -# @description ensure COMMAND_BIN_DIR env var is set -# and PATH correctly prepared -# @noargs -# @set COMMAND_BIN_DIR string the directory where to find this command -# @set PATH string add directory where to find this command binary -Compiler::Facade::requireCommandBinDir() { - COMMAND_BIN_DIR="${CURRENT_DIR}" - Env::pathPrepend "${COMMAND_BIN_DIR}" + +# @description create a temp file using default TMPDIR variable +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" } + declare -g FIRST_LOG_DATE LOG_LAST_LOG_DATE LOG_LAST_LOG_DATE_INIT LOG_LAST_DURATION_STR FIRST_LOG_DATE="${EPOCHREALTIME/[^0-9]/}" LOG_LAST_LOG_DATE="${FIRST_LOG_DATE}" @@ -818,30 +469,94 @@ Log::computeDuration() { fi } -# @description log message to file + +# @description Display message using debug color (gray) # @arg $1 message:String the message to display -Log::logInfo() { - if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_INFO)); then - Log::logMessage "${2:-INFO}" "$1" +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::displayDebug() { + if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_DEBUG)); then + Log::computeDuration + echo -e "${__DEBUG_COLOR}DEBUG - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 fi + Log::logDebug "$1" } -# @description log message to file + +# @description Display message using error color (red) # @arg $1 message:String the message to display -Log::logDebug() { - if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_DEBUG)); then - Log::logMessage "${2:-DEBUG}" "$1" +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::displayError() { + if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_ERROR)); then + Log::computeDuration + echo -e "${__ERROR_COLOR}ERROR - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 + fi + Log::logError "$1" +} + + +# @description Display message using info color (bg light blue/fg white) +# @arg $1 message:String the message to display +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::displayInfo() { + local type="${2:-INFO}" + if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_INFO)); then + Log::computeDuration + echo -e "${__INFO_COLOR}${type} - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 + fi + Log::logInfo "$1" "${type}" +} + + +# @description Display message using success color (bg green/fg white) +# @arg $1 message:String the message to display +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::displaySuccess() { + if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_INFO)); then + Log::computeDuration + echo -e "${__SUCCESS_COLOR}SUCCESS - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 + fi + Log::logSuccess "$1" +} + + +# @description Display message using warning color (yellow) +# @arg $1 message:String the message to display +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::displayWarning() { + if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_WARNING)); then + Log::computeDuration + echo -e "${__WARNING_COLOR}WARN - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 fi + Log::logWarning "$1" +} + + +# @description Display message using error color (red) and exit immediately with error status 1 +# @arg $1 message:String the message to display +# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs +# @env LOG_CONTEXT String allows to contextualize the log +Log::fatal() { + Log::computeDuration + echo -e "${__ERROR_COLOR}FATAL - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 + Log::logFatal "$1" + exit 1 } + # @description log message to file # @arg $1 message:String the message to display -Log::logWarning() { - if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_WARNING)); then - Log::logMessage "${2:-WARNING}" "$1" +Log::logDebug() { + if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_DEBUG)); then + Log::logMessage "${2:-DEBUG}" "$1" fi } + # @description log message to file # @arg $1 message:String the message to display Log::logError() { @@ -850,20 +565,6 @@ Log::logError() { fi } -# @description check if tty (interactive mode) is active -# @noargs -# @exitcode 1 if tty not active -# @env NON_INTERACTIVE if 1 consider as not interactive even if environment is interactive -# @env INTERACTIVE if 1 consider as interactive even if environment is not interactive -Assert::tty() { - if [[ "${NON_INTERACTIVE:-0}" = "1" ]]; then - return 1 - fi - if [[ "${INTERACTIVE:-0}" = "1" ]]; then - return 0 - fi - tty -s -} # @description log message to file # @arg $1 message:String the message to display @@ -871,6 +572,16 @@ Log::logFatal() { Log::logMessage "${2:-FATAL}" "$1" } + +# @description log message to file +# @arg $1 message:String the message to display +Log::logInfo() { + if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_INFO)); then + Log::logMessage "${2:-INFO}" "$1" + fi +} + + # @description Internal: common log message # @example text # [date]|[levelMsg]|message @@ -884,9 +595,18 @@ Log::logFatal() { # @env BASH_FRAMEWORK_LOG_FILE String log file to use, do nothing if empty # @env BASH_FRAMEWORK_LOG_LEVEL int log level log only if > OFF or fatal messages # @stderr diagnostics information is displayed -# @require Env::requireLoad -# @require Log::requireLoad Log::logMessage() { + + if [[ "${REQUIRE_FUNCTION_ENV_REQUIRE_LOAD_LOADED:-0}" != 1 ]]; then + echo >&2 "Requirement Env::requireLoad has not been loaded" + exit 1 + fi + + if [[ "${REQUIRE_FUNCTION_LOG_REQUIRE_LOAD_LOADED:-0}" != 1 ]]; then + echo >&2 "Requirement Log::requireLoad has not been loaded" + exit 1 + fi + local levelMsg="$1" local msg="$2" local date @@ -898,20 +618,97 @@ Log::logMessage() { fi } -# @description To be called before logging in the log file -# @arg $1 file:string log file name -# @arg $2 maxLogFilesCount:int maximum number of log files -Log::rotate() { - local file="$1" - local maxLogFilesCount="${2:-5}" - if [[ ! -f "${file}" ]]; then - Log::displayDebug "Log file ${file} doesn't exist yet" - return 0 +# @description log message to file +# @arg $1 message:String the message to display +Log::logSuccess() { + if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_INFO)); then + Log::logMessage "${2:-SUCCESS}" "$1" fi - local i - for ((i = maxLogFilesCount - 1; i > 0; i--)); do - Log::displayInfo "Log rotation ${file}.${i} to ${file}.$((i + 1))" +} + + +# @description log message to file +# @arg $1 message:String the message to display +Log::logWarning() { + if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_WARNING)); then + Log::logMessage "${2:-WARNING}" "$1" + fi +} + + +# @description activate or not Log::display* and Log::log* functions +# based on BASH_FRAMEWORK_DISPLAY_LEVEL and BASH_FRAMEWORK_LOG_LEVEL +# environment variables loaded by Env::requireLoad +# try to create log file and rotate it if necessary +# @noargs +# @set BASH_FRAMEWORK_LOG_LEVEL int to OFF level if BASH_FRAMEWORK_LOG_FILE is empty or not writable +# @env BASH_FRAMEWORK_DISPLAY_LEVEL int +# @env BASH_FRAMEWORK_LOG_LEVEL int +# @env BASH_FRAMEWORK_LOG_FILE String +# @env BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION int do log rotation if > 0 +# @exitcode 0 always successful +# @stderr diagnostics information about log file is displayed +Log::requireLoad() { + export REQUIRE_FUNCTION_LOG_REQUIRE_LOAD_LOADED=1 + + + if [[ "${REQUIRE_FUNCTION_ENV_REQUIRE_LOAD_LOADED:-0}" != 1 ]]; then + echo >&2 "Requirement Env::requireLoad has not been loaded" + exit 1 + fi + + if [[ "${REQUIRE_FUNCTION_UI_REQUIRE_THEME_LOADED:-0}" != 1 ]]; then + echo >&2 "Requirement UI::requireTheme has not been loaded" + exit 1 + fi + + if [[ -z "${BASH_FRAMEWORK_LOG_FILE:-}" ]]; then + BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} + export BASH_FRAMEWORK_LOG_LEVEL + fi + + if ((BASH_FRAMEWORK_LOG_LEVEL > __LEVEL_OFF)); then + if [[ ! -f "${BASH_FRAMEWORK_LOG_FILE}" ]]; then + if [[ ! -d "${BASH_FRAMEWORK_LOG_FILE%/*}" ]]; then + if ! mkdir -p "${BASH_FRAMEWORK_LOG_FILE%/*}" 2>/dev/null; then + BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} + echo -e "${__ERROR_COLOR}ERROR - directory ${BASH_FRAMEWORK_LOG_FILE%/*} is not writable${__RESET_COLOR}" >&2 + fi + elif ! touch --no-create "${BASH_FRAMEWORK_LOG_FILE}" 2>/dev/null; then + BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} + echo -e "${__ERROR_COLOR}ERROR - File ${BASH_FRAMEWORK_LOG_FILE} is not writable${__RESET_COLOR}" >&2 + fi + elif [[ ! -w "${BASH_FRAMEWORK_LOG_FILE}" ]]; then + BASH_FRAMEWORK_LOG_LEVEL=${__LEVEL_OFF} + echo -e "${__ERROR_COLOR}ERROR - File ${BASH_FRAMEWORK_LOG_FILE} is not writable${__RESET_COLOR}" >&2 + fi + fi + + if ((BASH_FRAMEWORK_LOG_LEVEL > __LEVEL_OFF)); then + # will always be created even if not in info level + Log::logMessage "INFO" "Logging to file ${BASH_FRAMEWORK_LOG_FILE} - Log level ${BASH_FRAMEWORK_LOG_LEVEL}" + if ((BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION > 0)); then + Log::rotate "${BASH_FRAMEWORK_LOG_FILE}" "${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION}" + fi + fi +} + + +# @description To be called before logging in the log file +# @arg $1 file:string log file name +# @arg $2 maxLogFilesCount:int maximum number of log files +Log::rotate() { + local file="$1" + local maxLogFilesCount="${2:-5}" + + if [[ ! -f "${file}" ]]; then + Log::displayDebug "Log file ${file} doesn't exist yet" + return 0 + fi + local i + for ((i = maxLogFilesCount - 1; i > 0; i--)); do + Log::displayInfo "Log rotation ${file}.${i} to ${file}.$((i + 1))" mv "${file}."{"${i}","$((i + 1))"} &>/dev/null || true done if cp "${file}" "${file}.1" &>/dev/null; then @@ -920,72 +717,108 @@ Log::rotate() { fi } -# @description check if an element is contained in an array -# -# @arg $1 needle:String -# @arg $@ array:String[] -# @exitcode 0 if found -# @exitcode 1 otherwise -# @example -# Array::contains "${libPath}" "${__BASH_FRAMEWORK_IMPORTED_FILES[@]}" -Array::contains() { - local element - for element in "${@:2}"; do - [[ "${element}" = "$1" ]] && return 0 - done - return 1 -} -# @description config directory path relative to current execution directory -# @arg $1 configFile:String the config file -# @stdout the parent directory of config file relative to current execution directory -# @example -# executionPath=/home/wsl/bash-tools -# configPath=/home/wsl/bash-tools/conf/postmanCli/openApis.json -# result=conf/postmanCli -Postman::Model::getRelativeConfigDirectory() { - local configFile="$1" - local configDir - configDir="$(cd -- "$(dirname -- "${configFile}")" &>/dev/null && pwd -P)" - File::relativeToDir "${configDir}" "$(pwd -P)" +# @description retrieve the collection id +# associated to the given collection name +# from the postman collection file +# @arg $1 collectionFile:String +# @arg $2 collectionName:String +# @exitcode 1 if error while parsing the collection file +# @exitcode 2 if name not found +# @exitcode 3 if more than one collection matches that name +# @stderr details, on failure +# @stdout the collection id associated to a unique collection name +Postman::Collection::getCollectionIdByName() { + local collectionFile="$1" + local collectionName="$2" + local result + local errorCode="0" + result="$( + jq -cre --arg name "${collectionName}" \ + '.collections[] | select( .name == $name) | .id' 2>&1 <"${collectionFile}" + )" || errorCode="$?" + if [[ "${errorCode}" = "4" ]]; then + Log::displayWarning "collection name '${collectionName}' not found in '${collectionFile}'" + return 2 + elif [[ "${errorCode}" != "0" ]]; then + Log::displayError "Error while parsing '${collectionFile}' - error code ${errorCode} - ${result}" + return 1 + fi + if (($(wc -l <<<"${result}") > 1)); then + Log::displayError "More than one collection match the collection name '${collectionName}', please clean up your postman workspace" + return 3 + fi + echo "${result}" } -# @description get the list of collection references id from given config file -# @arg $1 configFile:String the config file to parse -# @arg $2 getCollectionRefs:&String[] (passed by reference) list of collection -# references -# @exitcode 1 - if jq parsing error, file not found or any other error -# @stderr jq error messages on failure -Postman::Model::getCollectionRefs() { - local configFile="$1" - local -n getCollectionRefs=$2 - # shellcheck disable=SC2034 - jq -cre '.collections | try keys[]' <"${configFile}" | readarray -t getCollectionRefs + +# @description retrieve the name of the collection file +# from the postman collection file +# @arg $1 collectionFile:String +# @exitcode 1 if error while parsing the collection file +# @exitcode * jq exit code, 4 for invalid file +# @stdout the collection name of the collection file +Postman::Collection::getName() { + local collectionFile="$1" + jq -cre '.info.name' <"${collectionFile}" } -# @description check that each collection references passed as parameter -# exists in the model file -# @arg $1 modelFile:String model file in which availableRefs have been retrieved -# @arg $2 availableRefs:&String[] list of known collection references -# @arg $3 modelCollectionRefs:&String[] list of collection references to check -Postman::Model::checkIfValidCollectionRefs() { + +# @description apply callback on each collection specified by modelFile +# #### callback arguments +# - modelFile +# - postmanCollectionsFile +# - collectionRef +# - collectionFile +# - collectionName +# - postmanCollectionId +# - postmanCollectionIdStatus +# @arg $1 modelFile:String model file containing the collections to be processed +# @arg $2 callback:Function callback to apply on each collection selected +# @arg $@ list of collection references to process (all if not provided) +# @stderr diagnostic logs +# @exitcode 2 if no refs specified +# @exitcode * if one of sub commands fails +Postman::Commands::forEachCollection() { local modelFile="$1" - local -n availableRefs=$2 + local callback="$2" shift 2 || true - local -a modelCollectionRefs=("$@") + local -a refs=("$@") + + if ((${#refs[@]} == 0)); then + return 2 + fi + Postman::checkApiKey "${HOME}/.bash-tools/.env" || return 1 + local postmanCollectionsFile + postmanCollectionsFile="$(Framework::createTempFile "postmanCollections")" # shellcheck disable=SC2154 - Log::displayDebug "Checking collection refs using config ${modelFile}" + Log::displayDebug "Retrieving collections from postman in ${postmanCollectionsFile}" + Postman::api getCollections >"${postmanCollectionsFile}" || return 1 - local ref - for ref in "${modelCollectionRefs[@]}"; do - if ! Array::contains "${ref}" "${availableRefs[@]}"; then - Log::displayError "Collection ref '${ref}' is not known in '${modelFile}'" - return 1 - fi + local collectionRef + for collectionRef in "${refs[@]}"; do + local collectionFile collectionName postmanCollectionId + Log::displayDebug "Retrieving collection file from collection reference ${collectionRef}" + collectionFile="$(Postman::Model::getCollectionFileByRef "${modelFile}" "${collectionRef}")" + Log::displayDebug "Retrieving collection name from collection file ${collectionFile}" + collectionName="$(Postman::Collection::getName "${collectionFile}")" + Log::displayDebug "Deducing postman collection id using ${postmanCollectionsFile} and collection name '${collectionName}'" + local postmanCollectionIdStatus="0" + postmanCollectionId="$(Postman::Collection::getCollectionIdByName "${postmanCollectionsFile}" "${collectionName}")" || status=$? + local status=0 + "${callback}" \ + "${modelFile}" "${postmanCollectionsFile}" \ + "${collectionRef}" "${collectionFile}" "${collectionName}" \ + "${postmanCollectionId}" "${postmanCollectionIdStatus}" || status=$? + case "${status}" in + 2 | 0) continue ;; + *) return 1 ;; + esac done } + # @description pull collections specified by modelFile # @arg $1 modelFile:String model file containing the collections to be pulled # @arg $@ list of collection references to pull (all if not provided) @@ -1029,6 +862,37 @@ Postman::Commands::pullCollections() { Postman::Commands::forEachCollection "${modelFile}" pullCollectionsCallback "$@" } + +# @description validate arguments before calling Postman::Commands::pullCollections +# @arg $1 modelFile:String model file containing the collections to be pulled +# @arg $@ list of collection references to pull (all if not provided) +# @stderr diagnostic logs +# @exitcode * if one of sub commands fails +Postman::Commands::pullCommand() { + local modelFile="$1" + shift || true + + Postman::Model::validate "${modelFile}" "pull" || return 1 + + local -a refs + # shellcheck disable=SC2154 + Postman::Model::getCollectionRefs "${modelFile}" refs || return 1 + if (($# > 0)); then + # shellcheck disable=SC2154 + Postman::Model::checkIfValidCollectionRefs "${modelFile}" refs "$@" || return 1 + refs=("$@") + fi + + if ((${#refs} == 0)); then + Log::displayError "No collection refs to pull" + return 1 + else + Log::displayDebug "Collection refs to pull ${refs[*]}" + Postman::Commands::pullCollections "${modelFile}" "${refs[@]}" || return 1 + fi +} + + # @description push collections specified by modelFile # @arg $1 modelFile:String model file containing the collections to be pushed # @arg $@ list of collection references to push (all if not provided) @@ -1069,41 +933,216 @@ Postman::Commands::pushCollections() { Postman::Commands::forEachCollection "${modelFile}" pushCollectionsCallback "$@" } -# @description prepend directories to the PATH environment variable -# @arg $@ args:String[] list of directories to prepend -# @set PATH update PATH with the directories prepended -Env::pathPrepend() { - local arg - for arg in "$@"; do - if [[ -d "${arg}" && ":${PATH}:" != *":${arg}:"* ]]; then - PATH="$(realpath "${arg}"):${PATH}" - fi - done -} -# @description load color theme -# @noargs -# @env BASH_FRAMEWORK_THEME String theme to use -# @env LOAD_THEME int 0 to avoid loading theme -# @exitcode 0 always successful -UI::requireTheme() { - if [[ "${LOAD_THEME:-1}" = "1" ]]; then - UI::theme "${BASH_FRAMEWORK_THEME-default}" +# @description validate arguments before calling Postman::Commands::pushCollections +# @arg $1 modelFile:String model file containing the collections to be pushed +# @arg $@ list of collection references to push (all if not provided) +# @stderr diagnostic logs +# @exitcode * if one of sub commands fails +Postman::Commands::pushCommand() { + local modelFile="$1" + shift || true + + Postman::Model::validate "${modelFile}" "push" || return 1 + + local -a refs + # shellcheck disable=SC2154 + Postman::Model::getCollectionRefs "${modelFile}" refs || return 1 + if (($# > 0)); then + # shellcheck disable=SC2154 + Postman::Model::checkIfValidCollectionRefs "${modelFile}" refs "$@" || return 1 + refs=("$@") + fi + + if ((${#refs} == 0)); then + Log::displayError "No collection refs to push" + return 1 + else + Log::displayDebug "Collection refs to push ${refs[*]}" + Postman::Commands::pushCollections "${modelFile}" "${refs[@]}" || return 1 fi } -# @description print the resolved path relative to DIR -# do not check for path existence -# @arg $1 srcFile:String the file to resolve -# @arg $2 relativeTo:String the directory -# @stdout the resolved path relative to DIR -File::relativeToDir() { - local srcFile="$1" - local relativeTo="$2" - realpath -m --relative-to="${relativeTo}" "${srcFile}" +# @description check that each collection references passed as parameter +# exists in the model file +# @arg $1 modelFile:String model file in which availableRefs have been retrieved +# @arg $2 availableRefs:&String[] list of known collection references +# @arg $3 modelCollectionRefs:&String[] list of collection references to check +Postman::Model::checkIfValidCollectionRefs() { + local modelFile="$1" + local -n availableRefs=$2 + shift 2 || true + local -a modelCollectionRefs=("$@") + + # shellcheck disable=SC2154 + Log::displayDebug "Checking collection refs using config ${modelFile}" + + local ref + for ref in "${modelCollectionRefs[@]}"; do + if ! Array::contains "${ref}" "${availableRefs[@]}"; then + Log::displayError "Collection ref '${ref}' is not known in '${modelFile}'" + return 1 + fi + done +} + + +# @description retrieve the file associated to the collection ref +# @arg $1 configFile:String the config file to parse +# @arg $2 ref:String the collection reference to get +# @stdout the file relative to current execution directory +# @exitcode 1 - if jq parsing error, file not found or any other error +Postman::Model::getCollectionFileByRef() { + local configFile="$1" + local ref="$2" + local file + file="$(jq -cre ".collections.${ref}.file" <"${configFile}")" || return 1 + echo "$(Postman::Model::getRelativeConfigDirectory "${configFile}")/${file}" +} + + +# @description get the list of collection references id from given config file +# @arg $1 configFile:String the config file to parse +# @arg $2 getCollectionRefs:&String[] (passed by reference) list of collection +# references +# @exitcode 1 - if jq parsing error, file not found or any other error +# @stderr jq error messages on failure +Postman::Model::getCollectionRefs() { + local configFile="$1" + local -n getCollectionRefs=$2 + # shellcheck disable=SC2034 + jq -cre '.collections | try keys[]' <"${configFile}" | readarray -t getCollectionRefs +} + + +# @description config directory path relative to current execution directory +# @arg $1 configFile:String the config file +# @stdout the parent directory of config file relative to current execution directory +# @example +# executionPath=/home/wsl/bash-tools +# configPath=/home/wsl/bash-tools/conf/postmanCli/openApis.json +# result=conf/postmanCli +Postman::Model::getRelativeConfigDirectory() { + local configFile="$1" + local configDir + configDir="$(cd -- "$(dirname -- "${configFile}")" &>/dev/null && pwd -P)" + File::relativeToDir "${configDir}" "$(pwd -P)" +} + + +# @description validates the model file and checks for file existence +# @arg $1 optionModelFile:String the model file to validate +# @arg $2 mode:Enum(pull|push|config) eg: pull/config don't check for file existence +# @exitcode 1 if file optionModelFile does not exists or invalid +# @stderr diagnostics information is displayed +Postman::Model::validate() { + local modelFile="$1" + local mode="$2" + + if ! Array::contains "${mode}" pull push config; then + Log::displayError "invalid mode ${mode}" + return 1 + fi + + # shellcheck disable=SC2154 + if [[ ! -f "${modelFile}" ]]; then + Log::displayError "File ${modelFile} does not exist" + return 1 + fi + + if ! jq -cre . &>/dev/null <"${modelFile}"; then + Log::displayError "File '${modelFile}' is not a valid json file" + return 1 + fi + local -i errorCount=0 + + # check name key presence + local name + name="$(jq -cre .name 2>/dev/null <"${modelFile}")" || { + Log::displayError "File '${modelFile}' - missing name property" + ((++errorCount)) + } + if [[ -z "${name}" ]]; then + Log::displayError "File '${modelFile}' name property cannot be empty" + ((++errorCount)) + fi + + # check collections key presence + local expr='.collections | if type=="object" then "yes" else "no" end' + if [[ "$(jq -cre "${expr}" <"${modelFile}")" = "no" ]]; then + Log::displayError "File '${modelFile}' - collections property is missing or is not an object" + ((++errorCount)) + else + local collectionJson + local -i index=0 + # shellcheck disable=SC2030 + jq -cre '.collections | to_entries | map(.value + {key: .key}) | .[]' "${modelFile}" | while IFS=$'\n' read -r collectionJson; do + local collectionFile collectionKey + local status=0 + collectionFile="$(jq -cre .file 2>/dev/null <<<"${collectionJson}")" || status=1 + if [[ "${status}" = 0 ]]; then + collectionKey="$(jq -cre .key 2>/dev/null <<<"${collectionJson}")" || status=1 + else + collectionKey="${index}" + fi + if [[ "${status}" = 1 ]]; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - missing file property" + ((++errorCount)) + else + local configDirectory + configDirectory="$(Postman::Model::getRelativeConfigDirectory "${modelFile}")" + collectionFile="${configDirectory}/${collectionFile}" + case "${mode}" in + push) + if [[ ! -f "${collectionFile}" ]]; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} does not exists" + ((++errorCount)) + continue + fi + if [[ ! -r "${collectionFile}" ]]; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not readable" + ((++errorCount)) + continue + fi + if ! jq -cre . &>/dev/null <"${collectionFile}"; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not a valid json file" + ((++errorCount)) + continue + fi + if ! jq -cre .info.name &>/dev/null <"${collectionFile}"; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} does not seem to be a valid collection file" + ((++errorCount)) + continue + fi + ;; + + pull) + if [[ -f "${collectionFile}" && ! -w "${collectionFile}" ]]; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - collection file ${collectionFile} is not writable" + ((++errorCount)) + continue + fi + if [[ ! -f "${collectionFile}" && ! -w "${configDirectory}" ]]; then + Log::displayError "File '${modelFile}' - collection ${collectionKey} - config directory ${configDirectory} is not writable" + ((++errorCount)) + continue + fi + ;; + *) ;; + # ignore + esac + fi + # TODO environment + ((++index)) + done + fi + + # shellcheck disable=SC2031 + ((errorCount == 0)) } + # @description call postman REST api # @arg $1 action:String action to call # @arg $@ args:String[] rest of arguments @@ -1203,101 +1242,20 @@ Postman::api() { esac } -# @description Display message using success color (bg green/fg white) -# @arg $1 message:String the message to display -# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs -# @env LOG_CONTEXT String allows to contextualize the log -Log::displaySuccess() { - if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_INFO)); then - Log::computeDuration - echo -e "${__SUCCESS_COLOR}SUCCESS - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2 + +# @description check if postman api key is set in .env file +# @arg $1 envFile:String .env file that should contain POSTMAN_API_KEY variable +# @stderr display warning message if postman api key is not filled +# @exitcode 0 always successful +Postman::checkApiKey() { + local envFile="$1" + + if grep -q '^POSTMAN_API_KEY=$' "${envFile}" 2>/dev/null || + ! grep -q '^POSTMAN_API_KEY=' "${envFile}" 2>/dev/null; then + Log::displayWarning "Please update POSTMAN_API_KEY in '${envFile}'" fi - Log::logSuccess "$1" } -# @description apply callback on each collection specified by modelFile -# #### callback arguments -# - modelFile -# - postmanCollectionsFile -# - collectionRef -# - collectionFile -# - collectionName -# - postmanCollectionId -# - postmanCollectionIdStatus -# @arg $1 modelFile:String model file containing the collections to be processed -# @arg $2 callback:Function callback to apply on each collection selected -# @arg $@ list of collection references to process (all if not provided) -# @stderr diagnostic logs -# @exitcode 2 if no refs specified -# @exitcode * if one of sub commands fails -Postman::Commands::forEachCollection() { - local modelFile="$1" - local callback="$2" - shift 2 || true - local -a refs=("$@") - - if ((${#refs[@]} == 0)); then - return 2 - fi - - Postman::checkApiKey "${HOME}/.bash-tools/.env" || return 1 - local postmanCollectionsFile - postmanCollectionsFile="$(Framework::createTempFile "postmanCollections")" - # shellcheck disable=SC2154 - Log::displayDebug "Retrieving collections from postman in ${postmanCollectionsFile}" - Postman::api getCollections >"${postmanCollectionsFile}" || return 1 - - local collectionRef - for collectionRef in "${refs[@]}"; do - local collectionFile collectionName postmanCollectionId - Log::displayDebug "Retrieving collection file from collection reference ${collectionRef}" - collectionFile="$(Postman::Model::getCollectionFileByRef "${modelFile}" "${collectionRef}")" - Log::displayDebug "Retrieving collection name from collection file ${collectionFile}" - collectionName="$(Postman::Collection::getName "${collectionFile}")" - Log::displayDebug "Deducing postman collection id using ${postmanCollectionsFile} and collection name '${collectionName}'" - local postmanCollectionIdStatus="0" - postmanCollectionId="$(Postman::Collection::getCollectionIdByName "${postmanCollectionsFile}" "${collectionName}")" || status=$? - local status=0 - "${callback}" \ - "${modelFile}" "${postmanCollectionsFile}" \ - "${collectionRef}" "${collectionFile}" "${collectionName}" \ - "${postmanCollectionId}" "${postmanCollectionIdStatus}" || status=$? - case "${status}" in - 2 | 0) continue ;; - *) return 1 ;; - esac - done -} - -# @description ignore exit code 141 from simple command pipes -# @example use with: -# local resultingStatus=0 -# local -a originalPipeStatus=() -# cmd1 | cmd2 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true -# [[ "${resultingStatus}" = "0" ]] -# @arg $1 resultingStatusCode:&int (passed by reference) (optional) resulting status code -# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array -# @env PIPESTATUS assuming that this function is called like in the example provided -# @see https://unix.stackexchange.com/a/709880/582856 -Bash::handlePipelineFailure() { - local -a pipeStatusBackup=("${PIPESTATUS[@]}") - local -n handlePipelineFailure_resultingStatusCode=$1 - local -n handlePipelineFailure_originalStatus=$2 - # shellcheck disable=SC2034 - handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}") - handlePipelineFailure_resultingStatusCode=0 - local statusCode - for statusCode in "${pipeStatusBackup[@]}"; do - if ((statusCode == 141)); then - return 0 - elif ((statusCode > 0)); then - # shellcheck disable=SC2034 - handlePipelineFailure_resultingStatusCode="${statusCode}" - break - fi - done - return "${handlePipelineFailure_resultingStatusCode}" -} # @description display curl response only if verbose mode is not off # @arg $1 type:String type of response displayed @@ -1315,124 +1273,227 @@ Postman::displayResponse() { fi } -# @description log message to file -# @arg $1 message:String the message to display -Log::logSuccess() { - if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_INFO)); then - Log::logMessage "${2:-SUCCESS}" "$1" + +# @description draw a line with the character passed in parameter repeated depending on terminal width +# @arg $1 character:String character to use as separator (default value #) +UI::drawLine() { + local character="${1:-#}" + local -i width=${COLUMNS:-0} + if ((width == 0)) && [[ -t 1 ]]; then + width=$(tput cols) + fi + if ((width == 0)); then + width=80 fi + printf -- "${character}%.0s" $(seq "${COLUMNS:-$([[ -t 1 ]] && tput cols || echo '80')}") + echo } -# @description check if postman api key is set in .env file -# @arg $1 envFile:String .env file that should contain POSTMAN_API_KEY variable -# @stderr display warning message if postman api key is not filled + +# @description load color theme +# @noargs +# @env BASH_FRAMEWORK_THEME String theme to use +# @env LOAD_THEME int 0 to avoid loading theme # @exitcode 0 always successful -Postman::checkApiKey() { - local envFile="$1" +UI::requireTheme() { + export REQUIRE_FUNCTION_UI_REQUIRE_THEME_LOADED=1 - if grep -q '^POSTMAN_API_KEY=$' "${envFile}" 2>/dev/null || - ! grep -q '^POSTMAN_API_KEY=' "${envFile}" 2>/dev/null; then - Log::displayWarning "Please update POSTMAN_API_KEY in '${envFile}'" + if [[ "${LOAD_THEME:-1}" = "1" ]]; then + UI::theme "${BASH_FRAMEWORK_THEME-default}" fi } -# @description retrieve the file associated to the collection ref -# @arg $1 configFile:String the config file to parse -# @arg $2 ref:String the collection reference to get -# @stdout the file relative to current execution directory -# @exitcode 1 - if jq parsing error, file not found or any other error -Postman::Model::getCollectionFileByRef() { - local configFile="$1" - local ref="$2" - local file - file="$(jq -cre ".collections.${ref}.file" <"${configFile}")" || return 1 - echo "$(Postman::Model::getRelativeConfigDirectory "${configFile}")/${file}" -} - -# @description retrieve the name of the collection file -# from the postman collection file -# @arg $1 collectionFile:String -# @exitcode 1 if error while parsing the collection file -# @exitcode * jq exit code, 4 for invalid file -# @stdout the collection name of the collection file -Postman::Collection::getName() { - local collectionFile="$1" - jq -cre '.info.name' <"${collectionFile}" -} -# @description retrieve the collection id -# associated to the given collection name -# from the postman collection file -# @arg $1 collectionFile:String -# @arg $2 collectionName:String -# @exitcode 1 if error while parsing the collection file -# @exitcode 2 if name not found -# @exitcode 3 if more than one collection matches that name -# @stderr details, on failure -# @stdout the collection id associated to a unique collection name -Postman::Collection::getCollectionIdByName() { - local collectionFile="$1" - local collectionName="$2" - local result - local errorCode="0" - result="$( - jq -cre --arg name "${collectionName}" \ - '.collections[] | select( .name == $name) | .id' 2>&1 <"${collectionFile}" - )" || errorCode="$?" - if [[ "${errorCode}" = "4" ]]; then - Log::displayWarning "collection name '${collectionName}' not found in '${collectionFile}'" - return 2 - elif [[ "${errorCode}" != "0" ]]; then - Log::displayError "Error while parsing '${collectionFile}' - error code ${errorCode} - ${result}" - return 1 +# @description load colors theme constants +# @warning if tty not opened, noColor theme will be chosen +# @arg $1 theme:String the theme to use (default, noColor) +# @arg $@ args:String[] +# @set __ERROR_COLOR String indicate error status +# @set __INFO_COLOR String indicate info status +# @set __SUCCESS_COLOR String indicate success status +# @set __WARNING_COLOR String indicate warning status +# @set __SKIPPED_COLOR String indicate skipped status +# @set __DEBUG_COLOR String indicate debug status +# @set __HELP_COLOR String indicate help status +# @set __TEST_COLOR String not used +# @set __TEST_ERROR_COLOR String not used +# @set __HELP_TITLE_COLOR String used to display help title in help strings +# @set __HELP_OPTION_COLOR String used to display highlight options in help strings +# +# @set __RESET_COLOR String reset default color +# +# @set __HELP_EXAMPLE String to remove +# @set __HELP_TITLE String to remove +# @set __HELP_NORMAL String to remove +# shellcheck disable=SC2034 +UI::theme() { + local theme="${1-default}" + if [[ ! "${theme}" =~ -force$ ]] && ! Assert::tty; then + theme="noColor" fi - if (($(wc -l <<<"${result}") > 1)); then - Log::displayError "More than one collection match the collection name '${collectionName}', please clean up your postman workspace" - return 3 + case "${theme}" in + default | default-force) + theme="default" + ;; + noColor) ;; + *) + Log::fatal "invalid theme provided" + ;; + esac + if [[ "${theme}" = "default" ]]; then + BASH_FRAMEWORK_THEME="default" + # check colors applicable https://misc.flogisoft.com/bash/tip_colors_and_formatting + __ERROR_COLOR='\e[31m' # Red + __INFO_COLOR='\e[44m' # white on lightBlue + __SUCCESS_COLOR='\e[32m' # Green + __WARNING_COLOR='\e[33m' # Yellow + __SKIPPED_COLOR='\e[33m' # Yellow + __DEBUG_COLOR='\e[37m' # Gray + __HELP_COLOR='\e[7;49;33m' # Black on Gold + __TEST_COLOR='\e[100m' # Light magenta + __TEST_ERROR_COLOR='\e[41m' # white on red + __HELP_TITLE_COLOR="\e[1;37m" # Bold + __HELP_OPTION_COLOR="\e[1;34m" # Blue + # Internal: reset color + __RESET_COLOR='\e[0m' # Reset Color + # shellcheck disable=SC2155,SC2034 + __HELP_EXAMPLE="$(echo -e "\e[2;97m")" + # shellcheck disable=SC2155,SC2034 + __HELP_TITLE="$(echo -e "\e[1;37m")" + # shellcheck disable=SC2155,SC2034 + __HELP_NORMAL="$(echo -e "\033[0m")" + else + BASH_FRAMEWORK_THEME="noColor" + # check colors applicable https://misc.flogisoft.com/bash/tip_colors_and_formatting + __ERROR_COLOR='' + __INFO_COLOR='' + __SUCCESS_COLOR='' + __WARNING_COLOR='' + __SKIPPED_COLOR='' + __DEBUG_COLOR='' + __HELP_COLOR='' + __TEST_COLOR='' + __TEST_ERROR_COLOR='' + __HELP_TITLE_COLOR='' + __HELP_OPTION_COLOR='' + # Internal: reset color + __RESET_COLOR='' + __HELP_EXAMPLE='' + __HELP_TITLE='' + __HELP_NORMAL='' fi - echo "${result}" } -# FUNCTIONS -facade_main_postmanClish() { -BASH_TOOLS_ROOT_DIR="$(cd "${CURRENT_DIR}/.." && pwd -P)" -if [[ -d "${BASH_TOOLS_ROOT_DIR}/vendor/bash-tools-framework/" ]]; then - FRAMEWORK_ROOT_DIR="$(cd "${BASH_TOOLS_ROOT_DIR}/vendor/bash-tools-framework" && pwd -P)" -else - # if the directory does not exist yet, give a value to FRAMEWORK_ROOT_DIR - FRAMEWORK_ROOT_DIR="${BASH_TOOLS_ROOT_DIR}/vendor/bash-tools-framework" -fi -FRAMEWORK_SRC_DIR="${FRAMEWORK_ROOT_DIR}/src" -FRAMEWORK_BIN_DIR="${FRAMEWORK_ROOT_DIR}/bin" -FRAMEWORK_VENDOR_DIR="${FRAMEWORK_ROOT_DIR}/vendor" -FRAMEWORK_VENDOR_BIN_DIR="${FRAMEWORK_ROOT_DIR}/vendor/bin" +# @description Check that command version is greater than expected minimal version +# display warning if command version greater than expected minimal version +# display error if command version less than expected minimal version and exit 1 +# @arg $1 commandName:String command path +# @arg $2 argVersion:String command line parameters to launch to get command version +# @arg $3 minimalVersion:String expected minimal command version +# @arg $4 parseVersionCallback:Function +# @arg $5 help:String optional help message to display if command does not exist +# @exitcode 0 if command version greater or equal to expected minimal version +# @exitcode 1 if command version less than expected minimal version +# @exitcode 2 if command does not exist +Version::checkMinimal() { + local commandName="$1" + local argVersion="$2" + local minimalVersion="$3" + local parseVersionCallback=${4:-Version::parse} + local help="${5:-}" -# @require BashTools::Conf::requireLoad -if [[ -f "${HOME}/.bash-tools/.env" ]]; then - export BASH_FRAMEWORK_ENV_FILES=("${HOME}/.bash-tools/.env") -fi -# REQUIRES -Env::requireLoad -UI::requireTheme -Log::requireLoad -BashTools::Conf::requireLoad -Compiler::Facade::requireCommandBinDir + Assert::commandExists "${commandName}" "${help}" || return 2 + + # shellcheck disable=SC2034 + local status=0 + # shellcheck disable=SC2034 + local -a pipeStatus=() + local version + version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback} || Bash::handlePipelineFailure status pipeStatus)" + + Log::displayDebug "check ${commandName} version ${version} against minimal ${minimalVersion}" + + Version::compare "${version}" "${minimalVersion}" || { + local result=$? + if [[ "${result}" = "1" ]]; then + Log::displayInfo "${commandName} version is ${version} greater than ${minimalVersion}" + elif [[ "${result}" = "2" ]]; then + Log::displayError "${commandName} minimal version is ${minimalVersion}, your version is ${version}" + return 1 + fi + return 0 + } -# @require Compiler::Facade::requireCommandBinDir +} -declare -a BASH_FRAMEWORK_ARGV_FILTERED=() -copyrightCallback() { - if [[ -z "${copyrightBeginYear}" ]]; then - copyrightBeginYear="$(date +%Y)" +# @description compare 2 version numbers +# @arg $1 version1:String version 1 +# @arg $2 version2:String version 2 +# @exitcode 0 if equal +# @exitcode 1 if version1 > version2 +# @exitcode 2 else +Version::compare() { + if [[ "$1" = "$2" ]]; then + return 0 fi - echo "Copyright (c) ${copyrightBeginYear}-now François Chastanet" + local IFS=. + # shellcheck disable=2206 + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do + ver1[i]=0 + done + for ((i = 0; i < ${#ver1[@]}; i++)); do + if [[ -z "${ver2[i]+unset}" ]] || [[ -z ${ver2[i]} ]]; then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})); then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})); then + return 2 + fi + done + return 0 } -# shellcheck disable=SC2317 # if function is overridden -updateArgListInfoVerboseCallback() { - BASH_FRAMEWORK_ARGV_FILTERED+=(--verbose) + +# @description filter to keep only version number from a string +# @arg $@ files:String[] the files to filter +# @exitcode * if one of the filter command fails +# @stdin you can use stdin as alternative to files argument +# @stdout the filtered content +# shellcheck disable=SC2120 +Version::parse() { + # match anything, print(p), exit on first match(Q) + sed -En \ + -e 's/\x1b\[[0-9;]*[mGKHF]//g' \ + -e 's/[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/' \ + -e '//{p;Q}' \ + "$@" +} +# FUNCTIONS + + +declare -a BASH_FRAMEWORK_ARGV_FILTERED=() + +beforeParseCallback() { + Env::requireLoad + UI::requireTheme + Log::requireLoad +} + +copyrightCallback() { + # + echo "Copyright (c) 2020-now François Chastanet" +} + +# shellcheck disable=SC2317 # if function is overridden +updateArgListInfoVerboseCallback() { + BASH_FRAMEWORK_ARGV_FILTERED+=(--verbose) } # shellcheck disable=SC2317 # if function is overridden updateArgListDebugVerboseCallback() { @@ -1459,13 +1520,14 @@ updateArgListQuietCallback() { :; } # shellcheck disable=SC2317 # if function is overridden optionHelpCallback() { - postmanCliCommand help + Log::displayError "optionHelpCallback needs to be overridden" exit 0 } # shellcheck disable=SC2317 # if function is overridden optionVersionCallback() { - echo "${SCRIPT_NAME} version 1.0" + # shellcheck disable=SC2154 + echo "${SCRIPT_NAME} version 3.0" exit 0 } @@ -1483,21 +1545,22 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { + # shellcheck disable=SC2034 BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >>"${overrideEnvFile}" } getLevel() { @@ -1521,6 +1584,7 @@ getLevel() { *) Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}" return 1 + ;; esac } @@ -1542,6 +1606,7 @@ getVerboseLevel() { *) Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}" return 1 + ;; esac } @@ -1552,7 +1617,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1561,19 +1626,20 @@ optionLogLevelCallback() { local logLevel verboseLevel logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" + # shellcheck disable=SC2034 BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" + echo "BASH_FRAMEWORK_QUIET_MODE=1" >>"${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1604,6 +1670,7 @@ optionBashFrameworkConfigCallback() { defaultFrameworkConfig="$( cat <<'EOF' + # copied from src/_includes/.framework-config.default # shellcheck disable=SC2034 @@ -1621,7 +1688,7 @@ NON_FRAMEWORK_FILES_REGEXP="${NON_FRAMEWORK_FILES_REGEXP:-(^bin/|.framework-conf # describe the files that are allowed to not have an associated bats file BATS_FILE_NOT_NEEDED_REGEXP="${BATS_FILE_NOT_NEEDED_REGEXP:-(^bin/|.framework-config|.bats$|/testsData/|^manualTests/|/_.sh$|/ZZZ.sh$|/__all.sh$|^src/batsHeaders.sh$|^src/_includes)}" # describe the files that are allowed to not have a function matching the filename -FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP="${FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP:-^bin/|^\.framework-config$|\.tpl$|/testsData/|^manualTests/|\.bats$}" +FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP="${FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP:-^bin/|^\.framework-config$|/testsData/|^manualTests/|\.bats$}" # Source directories if [[ ! -v FRAMEWORK_SRC_DIRS ]]; then FRAMEWORK_SRC_DIRS=( @@ -1637,6 +1704,7 @@ BASH_FRAMEWORK_LOG_LEVEL="${BASH_FRAMEWORK_LOG_LEVEL:-0}" BASH_FRAMEWORK_DISPLAY_LEVEL="${BASH_FRAMEWORK_DISPLAY_LEVEL:-3}" BASH_FRAMEWORK_LOG_FILE="${BASH_FRAMEWORK_LOG_FILE:-${FRAMEWORK_ROOT_DIR}/logs/${0##*/}.log}" BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5}" + EOF )" @@ -1645,7 +1713,7 @@ overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" commandOptionParseFinished() { # load default template framework config defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" - echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" + echo "${defaultFrameworkConfig}" >"${defaultEnvFile}" local -a files=("${defaultEnvFile}") if [[ -f "${envFile}" ]]; then files+=("${envFile}") @@ -1663,456 +1731,35 @@ commandOptionParseFinished() { fi } -postmanCliCommand() { - local options_parse_cmd="$1" - shift || true - if [[ "${options_parse_cmd}" = "parse" ]]; then - local -i options_parse_optionParsedCountOptionPostmanModelConfig - ((options_parse_optionParsedCountOptionPostmanModelConfig = 0)) || true - local -i options_parse_optionParsedCountOptionBashFrameworkConfig - ((options_parse_optionParsedCountOptionBashFrameworkConfig = 0)) || true - optionConfig="0" - local -i options_parse_optionParsedCountOptionConfig - ((options_parse_optionParsedCountOptionConfig = 0)) || true - optionInfoVerbose="0" - local -i options_parse_optionParsedCountOptionInfoVerbose - ((options_parse_optionParsedCountOptionInfoVerbose = 0)) || true - optionDebugVerbose="0" - local -i options_parse_optionParsedCountOptionDebugVerbose - ((options_parse_optionParsedCountOptionDebugVerbose = 0)) || true - optionTraceVerbose="0" - local -i options_parse_optionParsedCountOptionTraceVerbose - ((options_parse_optionParsedCountOptionTraceVerbose = 0)) || true - optionNoColor="0" - local -i options_parse_optionParsedCountOptionNoColor - ((options_parse_optionParsedCountOptionNoColor = 0)) || true - optionTheme="default" - local -i options_parse_optionParsedCountOptionTheme - ((options_parse_optionParsedCountOptionTheme = 0)) || true - optionHelp="0" - local -i options_parse_optionParsedCountOptionHelp - ((options_parse_optionParsedCountOptionHelp = 0)) || true - optionVersion="0" - local -i options_parse_optionParsedCountOptionVersion - ((options_parse_optionParsedCountOptionVersion = 0)) || true - optionQuiet="0" - local -i options_parse_optionParsedCountOptionQuiet - ((options_parse_optionParsedCountOptionQuiet = 0)) || true - local -i options_parse_optionParsedCountOptionLogLevel - ((options_parse_optionParsedCountOptionLogLevel = 0)) || true - local -i options_parse_optionParsedCountOptionLogFile - ((options_parse_optionParsedCountOptionLogFile = 0)) || true - local -i options_parse_optionParsedCountOptionDisplayLevel - ((options_parse_optionParsedCountOptionDisplayLevel = 0)) || true - local -i options_parse_argParsedCountArgCommand - ((options_parse_argParsedCountArgCommand = 0)) || true - local -i options_parse_argParsedCountCommandArgs - ((options_parse_argParsedCountCommandArgs = 0)) || true - # shellcheck disable=SC2034 - local -i options_parse_parsedArgIndex=0 - while (($# > 0)); do - local options_parse_arg="$1" - local argOptDefaultBehavior=0 - case "${options_parse_arg}" in - # Option 1/15 - # Option optionPostmanModelConfig --postman-model|-m variableType String min 0 max 1 authorizedValues '' regexp '' - --postman-model | -m) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if ((options_parse_optionParsedCountOptionPostmanModelConfig >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionPostmanModelConfig)) - # shellcheck disable=SC2034 - optionPostmanModelConfig="$1" - ;; - # Option 2/15 - # Option optionBashFrameworkConfig --bash-framework-config variableType String min 0 max 1 authorizedValues '' regexp '' - --bash-framework-config) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if ((options_parse_optionParsedCountOptionBashFrameworkConfig >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionBashFrameworkConfig)) - # shellcheck disable=SC2034 - optionBashFrameworkConfig="$1" - optionBashFrameworkConfigCallback "${options_parse_arg}" "${optionBashFrameworkConfig}" - ;; - # Option 3/15 - # Option optionConfig --config variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --config) - # shellcheck disable=SC2034 - optionConfig="1" - if ((options_parse_optionParsedCountOptionConfig >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionConfig)) - ;; - # Option 4/15 - # Option optionInfoVerbose --verbose|-v variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --verbose | -v) - # shellcheck disable=SC2034 - optionInfoVerbose="1" - if ((options_parse_optionParsedCountOptionInfoVerbose >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionInfoVerbose)) - optionInfoVerboseCallback "${options_parse_arg}" - updateArgListInfoVerboseCallback "${options_parse_arg}" - ;; - # Option 5/15 - # Option optionDebugVerbose -vv variableType Boolean min 0 max 1 authorizedValues '' regexp '' - -vv) - # shellcheck disable=SC2034 - optionDebugVerbose="1" - if ((options_parse_optionParsedCountOptionDebugVerbose >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionDebugVerbose)) - optionDebugVerboseCallback "${options_parse_arg}" - updateArgListDebugVerboseCallback "${options_parse_arg}" - ;; - # Option 6/15 - # Option optionTraceVerbose -vvv variableType Boolean min 0 max 1 authorizedValues '' regexp '' - -vvv) - # shellcheck disable=SC2034 - optionTraceVerbose="1" - if ((options_parse_optionParsedCountOptionTraceVerbose >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionTraceVerbose)) - optionTraceVerboseCallback "${options_parse_arg}" - updateArgListTraceVerboseCallback "${options_parse_arg}" - ;; - # Option 7/15 - # Option optionEnvFiles --env-file variableType StringArray min 0 max -1 authorizedValues '' regexp '' - --env-file) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - ((++options_parse_optionParsedCountOptionEnvFiles)) - optionEnvFiles+=("$1") - optionEnvFileCallback "${options_parse_arg}" "${optionEnvFiles[@]}" - updateArgListEnvFileCallback "${options_parse_arg}" "${optionEnvFiles[@]}" - ;; - # Option 8/15 - # Option optionNoColor --no-color variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --no-color) - # shellcheck disable=SC2034 - optionNoColor="1" - if ((options_parse_optionParsedCountOptionNoColor >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionNoColor)) - optionNoColorCallback "${options_parse_arg}" - updateArgListNoColorCallback "${options_parse_arg}" - ;; - # Option 9/15 - # Option optionTheme --theme variableType String min 0 max 1 authorizedValues 'default|default-force|noColor' regexp '' - --theme) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if [[ ! "$1" =~ default|default-force|noColor ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(default|default-force|noColor)" - return 1 - fi - if ((options_parse_optionParsedCountOptionTheme >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionTheme)) - # shellcheck disable=SC2034 - optionTheme="$1" - optionThemeCallback "${options_parse_arg}" "${optionTheme}" - updateArgListThemeCallback "${options_parse_arg}" "${optionTheme}" - ;; - # Option 10/15 - # Option optionHelp --help|-h variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --help | -h) - # shellcheck disable=SC2034 - optionHelp="1" - if ((options_parse_optionParsedCountOptionHelp >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionHelp)) - optionHelpCallback "${options_parse_arg}" - ;; - # Option 11/15 - # Option optionVersion --version variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --version) - # shellcheck disable=SC2034 - optionVersion="1" - if ((options_parse_optionParsedCountOptionVersion >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionVersion)) - optionVersionCallback "${options_parse_arg}" - ;; - # Option 12/15 - # Option optionQuiet --quiet|-q variableType Boolean min 0 max 1 authorizedValues '' regexp '' - --quiet | -q) - # shellcheck disable=SC2034 - optionQuiet="1" - if ((options_parse_optionParsedCountOptionQuiet >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionQuiet)) - optionQuietCallback "${options_parse_arg}" - updateArgListQuietCallback "${options_parse_arg}" - ;; - # Option 13/15 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' - --log-level) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" - return 1 - fi - if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionLogLevel)) - # shellcheck disable=SC2034 - optionLogLevel="$1" - optionLogLevelCallback "${options_parse_arg}" "${optionLogLevel}" - updateArgListLogLevelCallback "${options_parse_arg}" "${optionLogLevel}" - ;; - # Option 14/15 - # Option optionLogFile --log-file variableType String min 0 max 1 authorizedValues '' regexp '' - --log-file) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if ((options_parse_optionParsedCountOptionLogFile >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionLogFile)) - # shellcheck disable=SC2034 - optionLogFile="$1" - optionLogFileCallback "${options_parse_arg}" "${optionLogFile}" - updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" - ;; - # Option 15/15 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' - --display-level) - shift - if (($# == 0)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" - return 1 - fi - if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" - return 1 - fi - if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" - return 1 - fi - ((++options_parse_optionParsedCountOptionDisplayLevel)) - # shellcheck disable=SC2034 - optionDisplayLevel="$1" - optionDisplayLevelCallback "${options_parse_arg}" "${optionDisplayLevel}" - updateArgListDisplayLevelCallback "${options_parse_arg}" "${optionDisplayLevel}" - ;; - -*) - unknownOption "${options_parse_arg}" - ;; - *) - if ((0)); then - # Technical if - never reached - : - # Argument 1/2 - # Argument argCommand min 0 max 1 authorizedValues 'pull|push' regexp '' - elif ((options_parse_parsedArgIndex >= 0 && options_parse_parsedArgIndex < 1)); then - if [[ ! "${options_parse_arg}" =~ pull|push ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Argument command - value '${options_parse_arg}' is not part of authorized values(pull|push)" - return 1 - fi - if ((options_parse_argParsedCountArgCommand >= 1)); then - Log::displayError "Command ${SCRIPT_NAME} - Argument command - Maximum number of argument occurrences reached(1)" - return 1 - fi - ((++options_parse_argParsedCountArgCommand)) - # shellcheck disable=SC2034 - argCommand="${options_parse_arg}" - # Argument 2/2 - # Argument commandArgs min 0 max -1 authorizedValues '' regexp '' - elif ((options_parse_parsedArgIndex >= 1)); then - ((++options_parse_argParsedCountCommandArgs)) - # shellcheck disable=SC2034 - commandArgs+=("${options_parse_arg}") - else - unknownOption "${options_parse_arg}" - fi - ((++options_parse_parsedArgIndex)) - ;; - esac - shift || true - done - commandOptionParseFinished - Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}" - Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}" - elif [[ "${options_parse_cmd}" = "help" ]]; then - Array::wrap2 " " 80 0 "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" "Push/Pull postman collections of all the configured repositories" - echo - - echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "${SCRIPT_NAME}" "[OPTIONS]" "[ARGUMENTS]")" - echo -e "$(Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" \ - "${SCRIPT_NAME}" \ - "[--postman-model|-m ]" "[--bash-framework-config ]" "[--config]" "[--verbose|-v]" "[-vv]" "[-vvv]" "[--env-file ]" "[--no-color]" "[--theme ]" "[--help|-h]" "[--version]" "[--quiet|-q]" "[--log-level ]" "[--log-file ]" "[--display-level ]")" - echo - echo -e "${__HELP_TITLE_COLOR}ARGUMENTS:${__RESET_COLOR}" - echo -e " [${__HELP_OPTION_COLOR}command${__HELP_NORMAL} {single}]" - local -a helpArray - # shellcheck disable=SC2054,SC2206 - mapfile -t helpArray < <(argCommandHelp) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " [${__HELP_OPTION_COLOR}commandArgs${__HELP_NORMAL} {list} (optional)]" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=($'list of postman collection\'s references to pull or push\r\nor no argument to pull or push all the collections') - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo - echo -e "${__HELP_TITLE_COLOR}PUSH/PULL OPTIONS:${__RESET_COLOR}" - echo -e " ${__HELP_OPTION_COLOR}--postman-model${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-m ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=($'postmanCli model file to use\r\nDefault value: /postmanCli.collections.json') - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo - echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}" - echo -e " ${__HELP_OPTION_COLOR}--bash-framework-config ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(use\ alternate\ bash\ framework\ configuration.) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--config${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Display\ configuration) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--verbose${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-v${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(info\ level\ verbose\ mode\ \(alias\ of\ --display-level\ INFO\)) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}-vv${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(debug\ level\ verbose\ mode\ \(alias\ of\ --display-level\ DEBUG\)) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}-vvv${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(trace\ level\ verbose\ mode\ \(alias\ of\ --display-level\ TRACE\)) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--env-file ${__HELP_NORMAL} {list} (optional)" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Load\ the\ specified\ env\ file\ \(deprecated\,\ please\ use\ --bash-framework-config\ option\ instead\)) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--no-color${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Produce\ monochrome\ output.\ alias\ of\ --theme\ noColor.) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--theme ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' - echo ' Possible values: default|default-force|noColor' - echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Display\ this\ command\ help) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--version${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Print\ version\ information\ and\ quit) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--quiet${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-q${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(quiet\ mode\,\ doesn\'t\ display\ any\ output) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--log-level ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Set\ log\ level) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' - echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(Set\ log\ file) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo -e " ${__HELP_OPTION_COLOR}--display-level ${__HELP_NORMAL} {single}" - local -a helpArray - # shellcheck disable=SC2054 - helpArray=(set\ display\ level) - echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' - echo - echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}" - echo '1.0' - echo - echo -e "${__HELP_TITLE_COLOR}AUTHOR:${__RESET_COLOR}" - echo '[François Chastanet](https://github.com/fchastanet)' - echo - echo -e "${__HELP_TITLE_COLOR}SOURCE FILE:${__RESET_COLOR}" - echo 'https://github.com/fchastanet/bash-tools/tree/master/src/_binaries/Postman/postmanCli.sh' - echo - echo -e "${__HELP_TITLE_COLOR}LICENSE:${__RESET_COLOR}" - echo 'MIT License' - echo - Array::wrap2 ' ' 76 4 "$(copyrightCallback)" - else - Log::displayError "Command ${SCRIPT_NAME} - Option command invalid: '${options_parse_cmd}'" - return 1 - fi + +longDescriptionFunction() { + echo -e " ${__HELP_TITLE}EXIT CODES:${__HELP_NORMAL}" + echo -e " ${__HELP_OPTION_COLOR}1${__HELP_NORMAL}: if commit does not exists" + echo -e " ${__HELP_OPTION_COLOR}2${__HELP_NORMAL}: if ref is not convertible to commit oid" + echo -e " ${__HELP_OPTION_COLOR}3${__HELP_NORMAL}: if commit is not included in given branch" } -declare optionPostmanModelConfig="$(pwd -P)/postmanCli.collections.json" -declare copyrightBeginYear="2023" -argCommandHelp() { - echo "${__HELP_OPTION_COLOR}pull${__HELP_NORMAL}" $'\r' - echo " Pull collections from Postman back to repositories." $'\r' - echo "${__HELP_OPTION_COLOR}push${__HELP_NORMAL}" $'\r' - echo ' Push repositories collections to Postman.' +optionHelpCallback() { + postmanCliCommandHelp + exit 0 +} + +optionPostmanModelConfigHelpFunction() { + echo " postmanCli model file to use" + echo " Default value: /postmanCli.collections.json" +} + +argCommandHelpFunction() { + echo -e " ${__HELP_OPTION_COLOR}pull${__HELP_NORMAL}" + echo -e " Pull collections from Postman back to repositories." + echo -e " ${__HELP_OPTION_COLOR}push${__HELP_NORMAL}" + echo -e ' Push repositories collections to Postman.' +} + +commandArgsHelpFunction() { + echo -e " List of postman collection's references to pull or push" + echo -e " or no argument to pull or push all the collections" } # shellcheck disable=SC2317 # if function is overridden @@ -2120,39 +1767,692 @@ unknownOption() { commandArgs+=("$1") } +postmanCliCommandCallback() { + if [[ -z "${optionPostmanModelConfig}" ]]; then + optionPostmanModelConfig="${CURRENT_DIR}/postmanCli.collections.json" + fi + if [[ ! -f "${optionPostmanModelConfig}" ]]; then + Log::displayError "Please provide a valid postman config file, using --postman-model option." + exit 1 + fi + if [[ "${displayConfig}" = "1" ]]; then + # shellcheck disable=SC2154 + Postman::Model::validate "${optionPostmanModelConfig}" "config" + original_displayConfig + UI::drawLine "-" + printf '%-40s = %s\n' "POSTMAN_API_KEY" "${POSTMAN_API_KEY:0:15}...(truncated)" + exit 0 + fi +} + eval "original_$(declare -f displayConfig | grep -v 'exit 0')" +declare displayConfig=0 displayConfig() { - Postman::Model::validate "${optionPostmanModelConfig}" "config" - original_displayConfig - UI::drawLine "-" - printf '%-40s = %s\n' "POSTMAN_API_KEY" "${POSTMAN_API_KEY:0:15}...(truncated)" - exit 0 + displayConfig=1 } -# call main -postmanCliCommand parse "$@" -run() { + + + +optionVersionCallback() { # shellcheck disable=SC2154 - case "${argCommand}" in - pull) - Postman::Commands::pullCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" - ;; - push) - Postman::Commands::pushCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" - ;; - *) - Log::displayError "Invalid command ${argCommand}" - exit 1 - ;; - esac + echo "${SCRIPT_NAME} version 3.0" + Db::checkRequirements + exit 0 } -if [[ "${BASH_FRAMEWORK_QUIET_MODE:-0}" = "1" ]]; then - run "$@" &>/dev/null -else - run "$@" -fi + +# ------------------------------------------ +# Command postmanCliCommand +# ------------------------------------------ + +# options variables initialization +declare optionHelp="0" +declare optionConfig="0" +declare optionBashFrameworkConfig="" +declare optionInfoVerbose="0" +declare optionDebugVerbose="0" +declare optionTraceVerbose="0" +declare -a optionEnvFiles=() +declare optionLogLevel="" +declare optionLogFile="" +declare optionDisplayLevel="" +declare optionNoColor="0" +declare optionTheme="default" +declare optionVersion="0" +declare optionQuiet="0" +declare optionPostmanModelConfig="" +# arguments variables initialization +declare argCommand="" +declare commandArgs="" +# @description parse command options and arguments for postmanCliCommand +postmanCliCommandParse() { + Log::displayDebug "Command ${SCRIPT_NAME} - parse arguments: ${BASH_FRAMEWORK_ARGV[*]}" + Log::displayDebug "Command ${SCRIPT_NAME} - parse filtered arguments: ${BASH_FRAMEWORK_ARGV_FILTERED[*]}" + optionHelp="0" + local -i options_parse_optionParsedCountOptionHelp + ((options_parse_optionParsedCountOptionHelp = 0)) || true + optionConfig="0" + local -i options_parse_optionParsedCountOptionConfig + ((options_parse_optionParsedCountOptionConfig = 0)) || true + optionBashFrameworkConfig="" + local -i options_parse_optionParsedCountOptionBashFrameworkConfig + ((options_parse_optionParsedCountOptionBashFrameworkConfig = 0)) || true + optionInfoVerbose="0" + local -i options_parse_optionParsedCountOptionInfoVerbose + ((options_parse_optionParsedCountOptionInfoVerbose = 0)) || true + optionDebugVerbose="0" + local -i options_parse_optionParsedCountOptionDebugVerbose + ((options_parse_optionParsedCountOptionDebugVerbose = 0)) || true + optionTraceVerbose="0" + local -i options_parse_optionParsedCountOptionTraceVerbose + ((options_parse_optionParsedCountOptionTraceVerbose = 0)) || true + + optionLogLevel="" + local -i options_parse_optionParsedCountOptionLogLevel + ((options_parse_optionParsedCountOptionLogLevel = 0)) || true + optionLogFile="" + local -i options_parse_optionParsedCountOptionLogFile + ((options_parse_optionParsedCountOptionLogFile = 0)) || true + optionDisplayLevel="" + local -i options_parse_optionParsedCountOptionDisplayLevel + ((options_parse_optionParsedCountOptionDisplayLevel = 0)) || true + optionNoColor="0" + local -i options_parse_optionParsedCountOptionNoColor + ((options_parse_optionParsedCountOptionNoColor = 0)) || true + optionTheme="default" + local -i options_parse_optionParsedCountOptionTheme + ((options_parse_optionParsedCountOptionTheme = 0)) || true + optionVersion="0" + local -i options_parse_optionParsedCountOptionVersion + ((options_parse_optionParsedCountOptionVersion = 0)) || true + optionQuiet="0" + local -i options_parse_optionParsedCountOptionQuiet + ((options_parse_optionParsedCountOptionQuiet = 0)) || true + optionPostmanModelConfig="" + local -i options_parse_optionParsedCountOptionPostmanModelConfig + ((options_parse_optionParsedCountOptionPostmanModelConfig = 0)) || true + + argCommand="" + local -i options_parse_argParsedCountArgCommand + ((options_parse_argParsedCountArgCommand = 0)) || true + + commandArgs="" + + + # shellcheck disable=SC2034 + local -i options_parse_parsedArgIndex=0 + while (($# > 0)); do + local options_parse_arg="$1" + local argOptDefaultBehavior=0 + case "${options_parse_arg}" in + # Option 1/15 + # optionHelp alts --help|-h + # type: Boolean min 0 max 1 + --help | -h) + # shellcheck disable=SC2034 + optionHelp="1" + + if ((options_parse_optionParsedCountOptionHelp >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionHelp)) + optionHelpCallback "${options_parse_arg}" "${optionHelp}" + + ;; + + # Option 2/15 + # optionConfig alts --config + # type: Boolean min 0 max 1 + --config) + # shellcheck disable=SC2034 + optionConfig="1" + + if ((options_parse_optionParsedCountOptionConfig >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionConfig)) + ;; + + # Option 3/15 + # optionBashFrameworkConfig alts --bash-framework-config + # type: String min 0 max 1 + --bash-framework-config) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + + if ((options_parse_optionParsedCountOptionBashFrameworkConfig >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionBashFrameworkConfig)) + # shellcheck disable=SC2034 + optionBashFrameworkConfig="$1" + optionBashFrameworkConfigCallback "${options_parse_arg}" "${optionBashFrameworkConfig}" + + ;; + + # Option 4/15 + # optionInfoVerbose alts --verbose|-v + # type: Boolean min 0 max 1 + --verbose | -v) + # shellcheck disable=SC2034 + optionInfoVerbose="1" + + if ((options_parse_optionParsedCountOptionInfoVerbose >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionInfoVerbose)) + optionInfoVerboseCallback "${options_parse_arg}" "${optionInfoVerbose}" + + updateArgListInfoVerboseCallback "${options_parse_arg}" "${optionInfoVerbose}" + + ;; + + # Option 5/15 + # optionDebugVerbose alts -vv + # type: Boolean min 0 max 1 + -vv) + # shellcheck disable=SC2034 + optionDebugVerbose="1" + + if ((options_parse_optionParsedCountOptionDebugVerbose >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionDebugVerbose)) + optionDebugVerboseCallback "${options_parse_arg}" "${optionDebugVerbose}" + + updateArgListDebugVerboseCallback "${options_parse_arg}" "${optionDebugVerbose}" + + ;; + + # Option 6/15 + # optionTraceVerbose alts -vvv + # type: Boolean min 0 max 1 + -vvv) + # shellcheck disable=SC2034 + optionTraceVerbose="1" + + if ((options_parse_optionParsedCountOptionTraceVerbose >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionTraceVerbose)) + optionTraceVerboseCallback "${options_parse_arg}" "${optionTraceVerbose}" + + updateArgListTraceVerboseCallback "${options_parse_arg}" "${optionTraceVerbose}" + + ;; + + # Option 7/15 + # optionEnvFiles alts --env-file + # type: StringArray min 0 max -1 + --env-file) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + + ((++options_parse_optionParsedCountOptionEnvFiles)) + optionEnvFiles+=("$1") + optionEnvFileCallback "${options_parse_arg}" "${optionEnvFiles[@]}" + + updateArgListEnvFileCallback "${options_parse_arg}" "${optionEnvFiles[@]}" + + ;; + + # Option 8/15 + # optionLogLevel alts --log-level + # type: String min 0 max 1 + # authorizedValues: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE + --log-level) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values([OFF ERR ERROR WARN WARNING INFO DEBUG TRACE])" + return 1 + fi + + if ((options_parse_optionParsedCountOptionLogLevel >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionLogLevel)) + # shellcheck disable=SC2034 + optionLogLevel="$1" + optionLogLevelCallback "${options_parse_arg}" "${optionLogLevel}" + + updateArgListLogLevelCallback "${options_parse_arg}" "${optionLogLevel}" + + ;; + + # Option 9/15 + # optionLogFile alts --log-file + # type: String min 0 max 1 + --log-file) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + + if ((options_parse_optionParsedCountOptionLogFile >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionLogFile)) + # shellcheck disable=SC2034 + optionLogFile="$1" + optionLogFileCallback "${options_parse_arg}" "${optionLogFile}" + + updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" + + ;; + + # Option 10/15 + # optionDisplayLevel alts --display-level + # type: String min 0 max 1 + # authorizedValues: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE + --display-level) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values([OFF ERR ERROR WARN WARNING INFO DEBUG TRACE])" + return 1 + fi + + if ((options_parse_optionParsedCountOptionDisplayLevel >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionDisplayLevel)) + # shellcheck disable=SC2034 + optionDisplayLevel="$1" + optionDisplayLevelCallback "${options_parse_arg}" "${optionDisplayLevel}" + + updateArgListDisplayLevelCallback "${options_parse_arg}" "${optionDisplayLevel}" + + ;; + + # Option 11/15 + # optionNoColor alts --no-color + # type: Boolean min 0 max 1 + --no-color) + # shellcheck disable=SC2034 + optionNoColor="1" + + if ((options_parse_optionParsedCountOptionNoColor >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionNoColor)) + optionNoColorCallback "${options_parse_arg}" "${optionNoColor}" + + updateArgListNoColorCallback "${options_parse_arg}" "${optionNoColor}" + + ;; + + # Option 12/15 + # optionTheme alts --theme + # type: String min 0 max 1 + # authorizedValues: default|default-force|noColor + --theme) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + if [[ ! "$1" =~ default|default-force|noColor ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values([default default-force noColor])" + return 1 + fi + + if ((options_parse_optionParsedCountOptionTheme >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionTheme)) + # shellcheck disable=SC2034 + optionTheme="$1" + optionThemeCallback "${options_parse_arg}" "${optionTheme}" + + updateArgListThemeCallback "${options_parse_arg}" "${optionTheme}" + + ;; + + # Option 13/15 + # optionVersion alts --version + # type: Boolean min 0 max 1 + --version) + # shellcheck disable=SC2034 + optionVersion="1" + + if ((options_parse_optionParsedCountOptionVersion >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionVersion)) + optionVersionCallback "${options_parse_arg}" "${optionVersion}" + + ;; + + # Option 14/15 + # optionQuiet alts --quiet|-q + # type: Boolean min 0 max 1 + --quiet | -q) + # shellcheck disable=SC2034 + optionQuiet="1" + + if ((options_parse_optionParsedCountOptionQuiet >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionQuiet)) + optionQuietCallback "${options_parse_arg}" "${optionQuiet}" + + updateArgListQuietCallback "${options_parse_arg}" "${optionQuiet}" + + ;; + + # Option 15/15 + # optionPostmanModelConfig alts --postman-model|-m + # type: String min 0 max 1 + --postman-model | -m) + shift + if (($# == 0)); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" + return 1 + fi + + if ((options_parse_optionParsedCountOptionPostmanModelConfig >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - Maximum number of option occurrences reached(1)" + return 1 + fi + ((++options_parse_optionParsedCountOptionPostmanModelConfig)) + # shellcheck disable=SC2034 + optionPostmanModelConfig="$1" + ;; + + -*) + unknownOption "${options_parse_arg}" || argOptDefaultBehavior=$? + ;; + *) + ((minParsedArgIndex0 = 0)) || true + ((maxParsedArgIndex0 = 0)) || true + ((minParsedArgIndex1 = minParsedArgIndex0 + 0)) || true + ((maxParsedArgIndex1 = maxParsedArgIndex0 + 1)) || true + ((minParsedArgIndex2 = minParsedArgIndex1 + 0)) || true + ((maxParsedArgIndex2 = maxParsedArgIndex1)) || true + ((incrementArg = 1 )) + if ((0)); then + # Technical if - never reached + : + + # Argument 1/2 - argCommand + # Argument argCommand min 0 max 1 + # Argument argCommand authorizedValues: + elif (( options_parse_parsedArgIndex >= minParsedArgIndex0 && + options_parse_parsedArgIndex < maxParsedArgIndex1 )); then + if ((options_parse_argParsedCountArgCommand >= 1 )); then + Log::displayError "Command ${SCRIPT_NAME} - Argument command - Maximum number of argument occurrences reached(1)" + return 1 + fi + ((++options_parse_argParsedCountArgCommand)) + # shellcheck disable=SC2034 + argCommand="${options_parse_arg}" + + + # Argument 2/2 - commandArgs + # Argument commandArgs min 0 max -1 + # Argument commandArgs authorizedValues: + elif (( options_parse_parsedArgIndex >= minParsedArgIndex1 )); then + ((++options_parse_argParsedCountCommandArgs)) + # shellcheck disable=SC2034 + commandArgs="${options_parse_arg}" + + + # else too much args + else + + + # no arg configured, call unknownArgumentCallback + + # shellcheck disable=SC2317 + unknownOption "${options_parse_arg}" + + fi + if ((incrementArg == 1)); then + ((++options_parse_parsedArgIndex)) + fi + ;; + esac + shift || true + done || return $? + + + commandOptionParseFinished + postmanCliCommandCallback } -facade_main_postmanClish "$@" +# @description display command options and arguments help for postmanCliCommand +postmanCliCommandHelp() { + echo -e "${__HELP_TITLE_COLOR}SYNOPSIS:${__RESET_COLOR}" + Array::wrap2 ' ' 76 4 " " "Push/Pull postman collections of all the configured repositories." + + echo + echo + + # ------------------------------------------ + # usage section + # ------------------------------------------ + Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" "postmanCli [OPTIONS] [ARGUMENTS]" + echo + # ------------------------------------------ + # usage/options section + # ------------------------------------------ + optionsAltList=("[--help|-h]" "[--config]" "[--bash-framework-config ]" "[--verbose|-v]" "[-vv]" "[-vvv]" "[--env-file ]" "[--log-level ]" "[--log-file ]" "[--display-level ]" "[--no-color]" "[--theme ]" "[--version]" "[--quiet|-q]" "[--postman-model|-m ]" + ) + Array::wrap2 " " 80 2 "${__HELP_TITLE_COLOR}USAGE:${__RESET_COLOR}" \ + "postmanCli" "${optionsAltList[@]}" + echo + + # ------------------------------------------ + # usage/arguments section + # ------------------------------------------ + echo + echo -e "${__HELP_TITLE_COLOR}ARGUMENTS:${__RESET_COLOR}" + + Array::wrap2 " " 80 2 " [${__HELP_OPTION_COLOR}command${__HELP_NORMAL} {single}] + " + argCommandHelpFunction + + Array::wrap2 " " 80 2 " [${__HELP_OPTION_COLOR}ref${__HELP_NORMAL} {list} (optional)] + " + commandArgsHelpFunction + + # ------------------------------------------ + # options section + # ------------------------------------------ + echo + echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}" + echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Displays this command help" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--config${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Displays configuration" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--bash-framework-config ${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Use alternate bash framework configuration." + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--verbose${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-v${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Info level verbose mode (alias of --display-level INFO)" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}-vv${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Debug level verbose mode (alias of --display-level DEBUG)" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}-vvv${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Trace level verbose mode (alias of --display-level TRACE)" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--env-file ${__HELP_NORMAL} {list} (optional)" + Array::wrap2 ' ' 76 4 " " "Load the specified env file (deprecated, please use --bash-framework-config option instead)" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--log-level ${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Set log level" + echo + Array::wrap2 ' ' 76 6 " Possible values: " "OFF, " "ERR, " "ERROR, " "WARN, " "WARNING, " "INFO, " "DEBUG, " "TRACE" + echo + + + echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Set log file" + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--display-level ${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Set display level" + echo + Array::wrap2 ' ' 76 6 " Possible values: " "OFF, " "ERR, " "ERROR, " "WARN, " "WARNING, " "INFO, " "DEBUG, " "TRACE" + echo + + + echo -e " ${__HELP_OPTION_COLOR}--no-color${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Produce monochrome output. alias of --theme noColor." + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--theme ${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Choose color theme - default-force means colors will be produced even if command is piped." + echo + Array::wrap2 ' ' 76 6 " Possible values: " "default, " "default-force, " "noColor" + echo + + Array::wrap2 ' ' 76 6 " Default value: " "default" + echo + + echo -e " ${__HELP_OPTION_COLOR}--version${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Print version information and quit." + echo + + + + echo -e " ${__HELP_OPTION_COLOR}--quiet${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-q${__HELP_NORMAL} {single}" + Array::wrap2 ' ' 76 4 " " "Quiet mode, doesn't display any output." + echo + + + echo + echo -e "${__HELP_TITLE_COLOR}PUSH/PULL OPTIONS:${__RESET_COLOR}" + echo -e " ${__HELP_OPTION_COLOR}--postman-model${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-m ${__HELP_NORMAL} {single}" + optionPostmanModelConfigHelpFunction + + + + # ------------------------------------------ + # longDescription section + # ------------------------------------------ + echo + echo + echo -e "${__HELP_TITLE_COLOR}DESCRIPTION:${__RESET_COLOR}" + longDescriptionFunction + # ------------------------------------------ + # version section + # ------------------------------------------ + echo + echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}" + echo "3.0" + # ------------------------------------------ + # author section + # ------------------------------------------ + echo + echo -n -e "${__HELP_TITLE_COLOR}AUTHOR: ${__RESET_COLOR}" + echo "[François Chastanet](https://github.com/fchastanet)" + # ------------------------------------------ + # sourceFile section + # ------------------------------------------ + echo + echo -n -e "${__HELP_TITLE_COLOR}SOURCE FILE: ${__RESET_COLOR}" + echo "https://github.com/fchastanet/bash-tools-framework/tree/master/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml" + # ------------------------------------------ + # license section + # ------------------------------------------ + echo + echo -n -e "${__HELP_TITLE_COLOR}LICENSE: ${__RESET_COLOR}" + echo "MIT License" + # ------------------------------------------ + # copyright section + # ------------------------------------------ + Array::wrap2 ' ' 76 0 "$(copyrightCallback)" +} + + +beforeParseCallback + +postmanCliCommandParse "$@" +MAIN_FUNCTION_NAME="main" +main() { + +# shellcheck disable=SC2154 +case "${argCommand}" in + pull) + Postman::Commands::pullCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" + ;; + push) + Postman::Commands::pushCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" + ;; + *) + Log::displayError "Invalid command ${argCommand}" + exit 1 + ;; +esac + +} + +# if file is sourced avoid calling main function +# shellcheck disable=SC2178 +BASH_SOURCE=".$0" # cannot be changed in bash +# shellcheck disable=SC2128 +if test ".$0" == ".${BASH_SOURCE}"; then + if [[ "${BASH_FRAMEWORK_QUIET_MODE:-0}" = "1" ]]; then + main "$@" &>/dev/null + else + main "$@" + fi +fi diff --git a/src/_binaries/Postman/command.postmanCli.tpl b/src/_binaries/Postman/command.postmanCli.tpl deleted file mode 100644 index 95c17fa3..00000000 --- a/src/_binaries/Postman/command.postmanCli.tpl +++ /dev/null @@ -1,82 +0,0 @@ -% -declare versionNumber="1.0" -declare commandFunctionName="postmanCliCommand" -declare help="Push/Pull postman collections of all the configured repositories" -# shellcheck disable=SC2016 -% - -.INCLUDE "$(dynamicTemplateDir _binaries/options/options.base.tpl)" - -% - -# shellcheck source=/dev/null -source <( - Options::generateGroup \ - --title "PUSH/PULL OPTIONS:" \ - --function-name groupPushPullFunction - - # shellcheck disable=SC2016 - Options::generateOption \ - --variable-type String \ - --help $'postmanCli model file to use\r -Default value: /postmanCli.collections.json' \ - --group groupPushPullFunction \ - --alt "--postman-model" \ - --alt "-m" \ - --variable-name "optionPostmanModelConfig" \ - --function-name optionPostmanModelConfigFunction - - argCommandHelp() { :; } - Options::generateArg \ - --variable-name "argCommand" \ - --min 0 \ - --max 1 \ - --name "command" \ - --authorized-values 'pull|push' \ - --help argCommandHelp \ - --function-name argCommandFunction - - Options::generateArg \ - --variable-name "commandArgs" \ - --min 0 \ - --max -1 \ - --name "commandArgs" \ - --help \ - $'list of postman collection\'s references to pull or push\r -or no argument to pull or push all the collections' \ - --function-name commandArgsFunction -) - -options+=( - optionPostmanModelConfigFunction - argCommandFunction - commandArgsFunction - --unknown-option-callback unknownOption - --unknown-argument-callback unknownOption -) - -Options::generateCommand "${options[@]}" -% -declare optionPostmanModelConfig="$(pwd -P)/postmanCli.collections.json" -declare copyrightBeginYear="2024" - -argCommandHelp() { - echo "${__HELP_OPTION_COLOR}pull${__HELP_NORMAL}" $'\r' - echo " Pull collections from Postman back to repositories." $'\r' - echo "${__HELP_OPTION_COLOR}push${__HELP_NORMAL}" $'\r' - echo ' Push repositories collections to Postman.' -} - -# shellcheck disable=SC2317 # if function is overridden -unknownOption() { - commandArgs+=("$1") -} - -eval "original_$(declare -f displayConfig | grep -v 'exit 0')" -displayConfig() { - Postman::Model::validate "${optionPostmanModelConfig}" "config" - original_displayConfig - UI::drawLine "-" - printf '%-40s = %s\n' "POSTMAN_API_KEY" "${POSTMAN_API_KEY:0:15}...(truncated)" - exit 0 -} diff --git a/src/_binaries/Postman/postmanCli.sh b/src/_binaries/Postman/postmanCli.sh deleted file mode 100755 index d547a5bc..00000000 --- a/src/_binaries/Postman/postmanCli.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# BIN_FILE=${BASH_TOOLS_ROOT_DIR}/bin/postmanCli -# VAR_RELATIVE_FRAMEWORK_DIR_TO_CURRENT_DIR=.. -# FACADE - -.INCLUDE "$(dynamicTemplateDir _binaries/Postman/command.postmanCli.tpl)" -# call main -postmanCliCommand parse "$@" - -run() { - # shellcheck disable=SC2154 - case "${argCommand}" in - pull) - Postman::Commands::pullCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" - ;; - push) - Postman::Commands::pushCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" - ;; - *) - Log::displayError "Invalid command ${argCommand}" - exit 1 - ;; - esac -} - -if [[ "${BASH_FRAMEWORK_QUIET_MODE:-0}" = "1" ]]; then - run "$@" &>/dev/null -else - run "$@" -fi diff --git a/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml b/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml new file mode 100644 index 00000000..ed68379a --- /dev/null +++ b/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml @@ -0,0 +1,66 @@ +extends: + - "${BASH_TOOLS_ROOT_DIR}/src/_binaries/commandDefinitions/optionsVersion.yaml" + - "${FRAMEWORK_ROOT_DIR}/src/_binaries/commandDefinitions/defaultCommand.yaml" + - "${FRAMEWORK_ROOT_DIR}/src/_binaries/commandDefinitions/frameworkConfig.yaml" + +vars: + SRC_FILE_PATH: src/_binaries/Postman/postmanCli/postmanCli-binary.yaml + +compilerConfig: + targetFile: "${BASH_TOOLS_ROOT_DIR}/bin/postmanCli" + relativeRootDirBasedOnTargetDir: .. + srcDirs: + - ${BASH_TOOLS_ROOT_DIR}/src +binData: + commands: + default: + functionName: postmanCliCommand + version: "3.0" + copyrightBeginYear: 2020 + commandName: postmanCli + beforeParseCallbacks: + - beforeParseCallback + unknownOptionCallbacks: + - unknownOption + unknownArgumentCallbacks: + - unknownOption + callbacks: + - postmanCliCommandCallback + definitionFiles: + 20: ${BASH_TOOLS_ROOT_DIR}/src/_binaries/Postman/postmanCli/postmanCli-options.sh + mainFile: ${BASH_TOOLS_ROOT_DIR}/src/_binaries/Postman/postmanCli/postmanCli-main.sh + help: Push/Pull postman collections of all the configured repositories. + longDescription: longDescriptionFunction + args: + - type: String + min: 0 + max: 1 + help: argCommandHelpFunction + authorizedValues: + - value: pull + help: Pull + - value: push + help: Push + name: command + variableName: argCommand + + - type: String + min: 0 + max: -1 + help: commandArgsHelpFunction + name: ref + variableName: commandArgs + + optionGroups: + groupPushPull: + title: "PUSH/PULL OPTIONS:" + + options: + - variableName: optionPostmanModelConfig + type: String + group: groupPushPull + help: optionPostmanModelConfigHelpFunction + helpValueName: configFile + alts: + - --postman-model + - -m diff --git a/src/_binaries/Postman/postmanCli/postmanCli-main.sh b/src/_binaries/Postman/postmanCli/postmanCli-main.sh new file mode 100755 index 00000000..c2d0a606 --- /dev/null +++ b/src/_binaries/Postman/postmanCli/postmanCli-main.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# shellcheck disable=SC2154 +case "${argCommand}" in + pull) + Postman::Commands::pullCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" + ;; + push) + Postman::Commands::pushCommand "${optionPostmanModelConfig}" "${commandArgs[@]}" + ;; + *) + Log::displayError "Invalid command ${argCommand}" + exit 1 + ;; +esac diff --git a/src/_binaries/Postman/postmanCli/postmanCli-options.sh b/src/_binaries/Postman/postmanCli/postmanCli-options.sh new file mode 100755 index 00000000..0397dfb9 --- /dev/null +++ b/src/_binaries/Postman/postmanCli/postmanCli-options.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +longDescriptionFunction() { + echo -e " ${__HELP_TITLE}EXIT CODES:${__HELP_NORMAL}" + echo -e " ${__HELP_OPTION_COLOR}1${__HELP_NORMAL}: if commit does not exists" + echo -e " ${__HELP_OPTION_COLOR}2${__HELP_NORMAL}: if ref is not convertible to commit oid" + echo -e " ${__HELP_OPTION_COLOR}3${__HELP_NORMAL}: if commit is not included in given branch" +} + +optionHelpCallback() { + postmanCliCommandHelp + exit 0 +} + +optionPostmanModelConfigHelpFunction() { + echo " postmanCli model file to use" + echo " Default value: /postmanCli.collections.json" +} + +argCommandHelpFunction() { + echo -e " ${__HELP_OPTION_COLOR}pull${__HELP_NORMAL}" + echo -e " Pull collections from Postman back to repositories." + echo -e " ${__HELP_OPTION_COLOR}push${__HELP_NORMAL}" + echo -e ' Push repositories collections to Postman.' +} + +commandArgsHelpFunction() { + echo -e " List of postman collection's references to pull or push" + echo -e " or no argument to pull or push all the collections" +} + +# shellcheck disable=SC2317 # if function is overridden +unknownOption() { + commandArgs+=("$1") +} + +postmanCliCommandCallback() { + if [[ -z "${optionPostmanModelConfig}" ]]; then + optionPostmanModelConfig="${CURRENT_DIR}/postmanCli.collections.json" + fi + if [[ ! -f "${optionPostmanModelConfig}" ]]; then + Log::displayError "Please provide a valid postman config file, using --postman-model option." + exit 1 + fi + if [[ "${displayConfig}" = "1" ]]; then + # shellcheck disable=SC2154 + Postman::Model::validate "${optionPostmanModelConfig}" "config" + original_displayConfig + UI::drawLine "-" + printf '%-40s = %s\n' "POSTMAN_API_KEY" "${POSTMAN_API_KEY:0:15}...(truncated)" + exit 0 + fi +} + +eval "original_$(declare -f displayConfig | grep -v 'exit 0')" +declare displayConfig=0 +displayConfig() { + displayConfig=1 +} diff --git a/src/_binaries/Postman/postmanCli.bats b/src/_binaries/Postman/postmanCli/postmanCli.bats similarity index 61% rename from src/_binaries/Postman/postmanCli.bats rename to src/_binaries/Postman/postmanCli/postmanCli.bats index 58e334c1..71ddecfc 100755 --- a/src/_binaries/Postman/postmanCli.bats +++ b/src/_binaries/Postman/postmanCli/postmanCli.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck source=src/batsHeaders.sh -source "$(cd "${BATS_TEST_DIRNAME}/../.." && pwd)/batsHeaders.sh" +source "$(cd "${BATS_TEST_DIRNAME}/../../.." && pwd)/batsHeaders.sh" setup() { export TMPDIR="${BATS_TEST_TMPDIR}" @@ -21,18 +21,17 @@ function PostmanCli::display_help { #@test function PostmanCli::config { #@test run "${binDir}/postmanCli" --config -m "${rootDir}/conf/postmanCli/openApis.json" - + #assert_output "" assert_line --index 0 "Config" assert_line --index 1 "--------------------------------------------------------------------------------" assert_line --index 2 "BASH_FRAMEWORK_ARGV = ([0]=\"--config\" [1]=\"-m\" [2]=\"${rootDir}/conf/postmanCli/openApis.json\")" assert_line --index 3 "BASH_FRAMEWORK_ARGV_FILTERED = ()" assert_line --index 4 'BASH_FRAMEWORK_DISPLAY_LEVEL = "3"' - assert_line --index 5 "BASH_FRAMEWORK_ENV_FILES = ([0]=\"${HOME}/.bash-tools/.env\")" - assert_line --index 6 "BASH_FRAMEWORK_LOG_FILE = \"${TMPDIR}/logFile\"" - assert_line --index 7 'BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION = "5"' - assert_line --index 8 'BASH_FRAMEWORK_LOG_LEVEL = "0"' - assert_line --index 9 'BASH_FRAMEWORK_THEME = "default"' - assert_line --index 10 "--------------------------------------------------------------------------------" - assert_line --index 11 'POSTMAN_API_KEY = ...(truncated)' - assert_lines_count 12 + assert_line --index 5 "BASH_FRAMEWORK_LOG_FILE = \"${TMPDIR}/logFile\"" + assert_line --index 6 'BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION = "5"' + assert_line --index 7 'BASH_FRAMEWORK_LOG_LEVEL = "0"' + assert_line --index 8 'BASH_FRAMEWORK_THEME = "default"' + assert_line --index 9 "--------------------------------------------------------------------------------" + assert_line --index 10 'POSTMAN_API_KEY = ...(truncated)' + assert_lines_count 11 } diff --git a/src/_binaries/Postman/postmanCli/testsData/postmanCli.help.txt b/src/_binaries/Postman/postmanCli/testsData/postmanCli.help.txt new file mode 100644 index 00000000..78ef2487 --- /dev/null +++ b/src/_binaries/Postman/postmanCli/testsData/postmanCli.help.txt @@ -0,0 +1,76 @@ +SYNOPSIS: + Push/Pull postman collections of all the configured repositories. + +USAGE: postmanCli [OPTIONS] [ARGUMENTS] +USAGE: postmanCli [--help|-h] [--config] + [--bash-framework-config ] [--verbose|-v] [-vv] [-vvv] + [--env-file ] [--log-level ] [--log-file ] + [--display-level ] [--no-color] [--theme ] [--version] + [--quiet|-q] [--postman-model|-m ] + +ARGUMENTS: + [command {single}] + pull + Pull collections from Postman back to repositories. + push + Push repositories collections to Postman. + [ref {list} (optional)] + List of postman collection's references to pull or push + or no argument to pull or push all the collections + +GLOBAL OPTIONS: + --help, -h {single} + Displays this command help + --config {single} + Displays configuration + --bash-framework-config  {single} + Use alternate bash framework configuration. + --verbose, -v {single} + Info level verbose mode (alias of --display-level INFO) + -vv {single} + Debug level verbose mode (alias of --display-level DEBUG) + -vvv {single} + Trace level verbose mode (alias of --display-level TRACE) + --env-file  {list} (optional) + Load the specified env file (deprecated, please use --bash-framework-con + fig option instead) + --log-level  {single} + Set log level + Possible values: OFF, ERR, ERROR, WARN, WARNING, INFO, DEBUG, TRACE + --log-file  {single} + Set log file + --display-level  {single} + Set display level + Possible values: OFF, ERR, ERROR, WARN, WARNING, INFO, DEBUG, TRACE + --no-color {single} + Produce monochrome output. alias of --theme noColor. + --theme  {single} + Choose color theme - default-force means colors will be produced even if + command is piped. + Possible values: default, default-force, noColor + Default value: default + --version {single} + Print version information and quit. + --quiet, -q {single} + Quiet mode, doesn't display any output. + +PUSH/PULL OPTIONS: + --postman-model, -m  {single} + postmanCli model file to use + Default value: /postmanCli.collections.json + + +DESCRIPTION: + EXIT CODES: + 1: if commit does not exists + 2: if ref is not convertible to commit oid + 3: if commit is not included in given branch + +VERSION: 3.0 + +AUTHOR: [François Chastanet](https://github.com/fchastanet) + +SOURCE FILE: https://github.com/fchastanet/bash-tools-framework/tree/master/src/_binaries/Postman/postmanCli/postmanCli-binary.yaml + +LICENSE: MIT License +Copyright (c) 2020-now François Chastanet diff --git a/src/_binaries/Postman/testsData/postmanCli.help.txt b/src/_binaries/Postman/testsData/postmanCli.help.txt deleted file mode 100644 index 7165ecd9..00000000 --- a/src/_binaries/Postman/testsData/postmanCli.help.txt +++ /dev/null @@ -1,72 +0,0 @@ -DESCRIPTION: -Push/Pull postman collections of all the configured repositories -USAGE: postmanCli [OPTIONS] [ARGUMENTS] -USAGE: postmanCli [--postman-model|-m ] - [--bash-framework-config ] [--config] [--verbose|-v] [-vv] [-vvv] - [--env-file ] [--no-color] [--theme ] [--help|-h] [--version] - [--quiet|-q] [--log-level ] [--log-file ] - [--display-level ] - -ARGUMENTS: - [command {single}] - pull - Pull collections from Postman back to repositories. - push - Push repositories collections to Postman. - [commandArgs {list} (optional)] - list of postman collection's references to pull or push - or no argument to pull or push all the collections - -PUSH/PULL OPTIONS: - --postman-model, -m  {single} - postmanCli model file to use - Default value: /postmanCli.collections.json - -GLOBAL OPTIONS: - --bash-framework-config  {single} - use alternate bash framework configuration. - --config {single} - Display configuration - --verbose, -v {single} - info level verbose mode (alias of --display-level INFO) - -vv {single} - debug level verbose mode (alias of --display-level DEBUG) - -vvv {single} - trace level verbose mode (alias of --display-level TRACE) - --env-file  {list} (optional) - Load the specified env file (deprecated, please use --bash-framework-config - option instead) - --no-color {single} - Produce monochrome output. alias of --theme noColor. - --theme  {single} - choose color theme - default-force means colors will be produced even if com - mand is piped - Default value: default - Possible values: default|default-force|noColor - --help, -h {single} - Display this command help - --version {single} - Print version information and quit - --quiet, -q {single} - quiet mode, doesn't display any output - --log-level  {single} - Set log level - Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE - --log-file  {single} - Set log file - --display-level  {single} - set display level - Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE - -VERSION: 1.0 - -AUTHOR: -[François Chastanet](https://github.com/fchastanet) - -SOURCE FILE: -https://github.com/fchastanet/bash-tools/tree/master/src/_binaries/Postman/postmanCli.sh - -LICENSE: -MIT License - -Copyright (c) 2023-now François Chastanet