Skip to content

Commit

Permalink
compiled gitRenameBranch using go compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed Sep 4, 2024
1 parent d9f80f1 commit d7cb815
Show file tree
Hide file tree
Showing 21 changed files with 2,359 additions and 1,441 deletions.
147 changes: 145 additions & 2 deletions bin/gitIsAncestorOf
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,74 @@ Bash::handlePipelineFailure() {
}


# @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() {
Linux::requireTarCommand
Compiler::Embed::extractFileFromBase64 \
"${PERSISTENT_TMPDIR:-/tmp}/db87222729e0f1ed9c597a486a61a08c/bashToolsDefaultConfigTemplate" \
"IyEvdXNyL2Jpbi9lbnYgYmFzaAojIHNoZWxsY2hlY2sgZGlzYWJsZT1TQzIwMzQKCiMgRGVmYXVsdCBzZXR0aW5ncwojIHlvdSBjYW4gb3ZlcnJpZGUgdGhlc2Ugc2V0dGluZ3MgYnkgY3JlYXRpbmcgJHtIT01FfS8uYmFzaC10b29scy8uZW52IGZpbGUKCiMjIwojIyMgRElTUExBWSBMZXZlbAojIyMgbWluaW11bSBsZXZlbCBvZiB0aGUgbWVzc2FnZXMgdGhhdCB3aWxsIGJlIGRpc3BsYXllZCBvbiBzY3JlZW4KIyMjCiMjIyAwOiBOTyBMT0cKIyMjIDE6IEVSUk9SCiMjIyAyOiBXQVJOSU5HCiMjIyAzOiBJTkZPCiMjIyA0OiBERUJVRwojIyMKQkFTSF9GUkFNRVdPUktfRElTUExBWV9MRVZFTD0ke0JBU0hfRlJBTUVXT1JLX0RJU1BMQVlfTEVWRUw6LTN9CgojIyMKIyMjIERJU1BMQVkgZHVyYXRpb24KIyMjIDA6IG5vIGR1cmF0aW9uIGlzIGRpc3BsYXllZCBvbiB0aGUgbWVzc2FnZXMKIyMjIDE6IGR1cmF0aW9uIGJldHdlZW4gcHJldmlvdXMgbWVzc2FnZSBhbmQgY3VycmVudCBpcy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5IGRiSW1wb3J0L2RiSW1wb3J0VGFibGUKIyB0aGUgZmlsZSBtb2RpZmljYXRpb24gdGltZSBpcyBzZXQgdG8gbm93CkRCX0lNUE9SVF9HQVJCQUdFX0NPTExFQ1RfREFZUz0ke0RCX0lNUE9SVF9HQVJCQUdFX0NPTExFQ1RfREFZUzotKzMwfQoKIyBhYnNvbHV0ZSBkaXJlY3RvcnkgY29udGFpbmluZyBkYlNjcmlwdHMgdXNlZCBieSBkYlNjcmlwdEFsbERhdGFiYXNlcwpTQ1JJUFRTX0ZPTERFUj0ke1NDUklQVFNfRk9MREVSOi0ke0hPTUV9Ly5iYXNoLXRvb2xzL2NvbmYvZGJTY3JpcHRzfQoKIyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQojIEFXUyBQYXJhbWV0ZXJzCiMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KUzNfQkFTRV9VUkw9JHtTM19CQVNFX1VSTDotfQoKIyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQojIFBvc3RtYW4gUGFyYW1ldGVycwojIC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tClBPU1RNQU5fQVBJX0tFWT0K" \
"755"

declare -gx embed_file_bashToolsDefaultConfigTemplate="${PERSISTENT_TMPDIR:-/tmp}/db87222729e0f1ed9c597a486a61a08c/bashToolsDefaultConfigTemplate"

BASH_TOOLS_ROOT_DIR="$(cd "${CURRENT_DIR}/${RELATIVE_FRAMEWORK_DIR_TO_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
# shellcheck disable=SC2034
FRAMEWORK_SRC_DIR="${FRAMEWORK_ROOT_DIR}/src"
# shellcheck disable=SC2034
FRAMEWORK_BIN_DIR="${FRAMEWORK_ROOT_DIR}/bin"
# shellcheck disable=SC2034
FRAMEWORK_VENDOR_DIR="${FRAMEWORK_ROOT_DIR}/vendor"
# shellcheck disable=SC2034
FRAMEWORK_VENDOR_BIN_DIR="${FRAMEWORK_ROOT_DIR}/vendor/bin"

if [[ -f "${HOME}/.bash-tools/.env" ]]; then
# shellcheck disable=SC2034
BASH_FRAMEWORK_ENV_FILES=("${HOME}/.bash-tools/.env")
fi

local envFile="${HOME}/.bash-tools/.env"
if [[ ! -f "${envFile}" ]]; then
mkdir -p "${HOME}/.bash-tools"
(
echo "#!/usr/bin/env bash"
# shellcheck disable=SC2154
echo "${embed_file_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 run command specified
# @arg $@ array:String[] the command to run
# @env optionTraceVerbose int - if 1 displays the command specified before running it
# @env optionInfoVerbose int - if 1 displays the command specified before running it
# @env optionRedirectCmdOutputs String - if set redirect command outputs to file specified
# @exitcode command's exit code
BashTools::runVerboseIfNeeded() {
# shellcheck disable=SC2154
if [[ "${optionTraceVerbose}" = "1" ]]; then
if [[ "${optionInfoVerbose}" = "1" ]]; then
echo >&2 "+ $*"
fi
(
Expand All @@ -359,6 +419,36 @@ BashTools::runVerboseIfNeeded() {
}


# @description convert base64 encoded back to target file
# if target file is executable prepend dir of target
# file to PATH to make binary available everywhere
# it is advised to include in the path of the target file
# the md5sum of the binFile
#
# @arg $1 targetFile:String the file to write
# @arg $2 binFileBase64:String the base64 encoded file
# @arg $3 fileMode:String the chmod to set on the file
# @set PATH String prepend target embedded file binary directory to PATH variable if binary executable
Compiler::Embed::extractFileFromBase64() {
local targetFile="$1"
local binFileBase64="$2"
local fileMode="${3:-+x}"
local targetDir="${targetFile%/*}"

if [[ ! -f "${targetFile}" ]]; then
if [[ ! -d "${targetDir}" ]]; then
mkdir -p "${targetDir}"
fi
base64 -d >"${targetFile}" <<<"${binFileBase64}"
chmod "${fileMode}" "${targetFile}"
fi

if [[ -x "${targetFile}" ]]; then
Env::pathPrepend "${targetDir}"
fi
}


# @description check if all requirements are satisfied
# to execute dbImport commands
Db::checkRequirements() {
Expand All @@ -378,6 +468,19 @@ Db::checkRequirements() {
}


# @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 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
Expand Down Expand Up @@ -422,6 +525,24 @@ Framework::createTempFile() {
}


# @description ensure running user is not root
# @exitcode 1 if current user is root
# @stderr diagnostics information is displayed
Linux::requireExecutedAsUser() {
if [[ "$(id -u)" = "0" ]]; then
Log::fatal "this script should be executed as normal user"
fi
}


# @description ensure command tar is available
# @exitcode 1 if tar command not available
# @stderr diagnostics information is displayed
Linux::requireTarCommand() {
Assert::commandExists tar
}


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}"
Expand Down Expand Up @@ -1146,6 +1267,26 @@ commandOptionParseFinished() {



beforeParseCallback() {
Linux::requireExecutedAsUser
BashTools::Conf::requireLoad
Env::requireLoad
UI::requireTheme
Log::requireLoad
}

declare optionRedirectCmdOutputs=""
optionRedirectCmdOutputs() {
export optionTraceVerbose
# shellcheck disable=SC2154
if [[ "${optionTraceVerbose}" != "1" ]]; then
# shellcheck disable=SC2034 # used by BashTools::runVerboseIfNeeded
optionRedirectCmdOutputs="/dev/null"
fi
}



longDescriptionFunction() {
echo -e " ${__HELP_TITLE}EXIT CODES:${__HELP_NORMAL}"
echo -e " ${__HELP_OPTION_COLOR}1${__HELP_NORMAL}: if commit does not exists"
Expand Down Expand Up @@ -1620,7 +1761,9 @@ gitIsAncestorOfCommandParse() {
return 1
fi || return $?


commandOptionParseFinished
optionRedirectCmdOutputs

}

Expand Down
Loading

0 comments on commit d7cb815

Please sign in to comment.