Skip to content

Commit

Permalink
latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Kucherenko committed Jan 10, 2024
1 parent 00009e3 commit 639b26b
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 102 deletions.
7 changes: 5 additions & 2 deletions .scripts/_colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# shellcheck disable=SC2155

## Copyright (C) 2017-present, Oleksandr Kucherenko
## Last revisit: 2023-10-18
## Version: 1.0.0
## Last revisit: 2024-01-06
## Version: 1.0.1
## License: MIT
## Source: https://github.com/OleksandrKucherenko/e-bash

# shellcheck disable=SC2015 # one time initialization, CUID
[[ "${clr19adx10008og3819x1ipfv}" == "yes" ]] && return 0 || export clr19adx10008og3819x1ipfv="yes"

# tput calls require TERM to be set
if [[ -z $TERM ]]; then export TERM=xterm-256color; fi

Expand Down
28 changes: 14 additions & 14 deletions .scripts/_commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,23 @@ function env:variable:or:secret:file() {
#
local name=$1
local variable=$2
local file=$3
local filepath=$3
local fallback=${4:-"No hints, check the documentation"}
local __result=$name

if [[ -z "${!variable}" ]]; then
if [[ ! -f "$file" ]]; then
if [[ ! -f "$filepath" ]]; then
echo ""
echo "${cl_red}ERROR:${cl_reset} bash env variable '\$$variable' or file '$file' should be provided"
echo "${cl_red}ERROR:${cl_reset} bash env variable '\$$variable' or file '$filepath' should be provided"
echo ""
echo "Hint:"
echo " $fallback"
echo ""
echo:Common "Working Dir: $(pwd)"
return 1
else
echo "Using file: ${cl_green}$file${cl_reset} ~> $name"
eval $__result="'$(cat $file)'"
echo "Using file: ${cl_green}$filepath${cl_reset} ~> $name"
eval $__result="'$(cat $filepath)'"
fi
else
echo "Using var : ${cl_green}\$$variable${cl_reset} ~> $name"
Expand All @@ -291,17 +291,17 @@ function env:variable:or:secret:file:optional() {
#
local name=$1
local variable=$2
local file=$3
local filepath=$3
local __result=$name

if [[ -z "${!variable}" ]]; then
if [[ ! -f "$file" ]]; then
if [[ ! -f "$filepath" ]]; then
# NO variable, NO file
echo "${cl_yellow}Note:${cl_reset} bash env variable '\$$variable' or file '$file' can be provided."
echo "${cl_yellow}Note:${cl_reset} bash env variable '\$$variable' or file '$filepath' can be provided."
return 0
else
echo "Using file: ${cl_green}$file${cl_reset} ~> $name"
eval $__result="'$(cat $file)'"
echo "Using file: ${cl_green}$filepath${cl_reset} ~> $name"
eval $__result="'$(cat $filepath)'"

# make unit test happy, they expect 0 exit code, otherwise variable preserve will not work
${__SOURCED__:+x} && return 0 || return 2
Expand All @@ -319,14 +319,14 @@ function confirm:by:input() {
local hint=$1
local variable=$2
local fallback=$3
local first=$4
local top=$4
local second=$5
local third=$6
local masked=$7

print:confirmation() { echo "${cl_purple}? ${cl_reset}${hint}${cl_blue}$1${cl_reset}"; }

if [ -z "$first" ]; then
if [ -z "$top" ]; then
if [ -z "$second" ]; then
if [ -z "$third" ]; then
if [ -n "$masked" ]; then
Expand All @@ -343,8 +343,8 @@ function confirm:by:input() {
print:confirmation "${masked:-$second}"
fi
else
eval "$variable='$first'"
print:confirmation "${masked:-$first}"
eval "$variable='$top'"
print:confirmation "${masked:-$top}"
fi
}

Expand Down
Loading

0 comments on commit 639b26b

Please sign in to comment.