===================================================================== Big day! V4 is finally live. This INCLUDES some BREAKING CHANGES to ZSH TYPE scwrypts! Please refer to the readme for upgrade details (more specifically docs/upgrade/v3-to-v4.md) Upgrade is SUPER EASY, so please take the time to do so. --- New Features ---------------------------------------------------- - zsh type scwrypts have an upgraded runstring to improve context setup and simplicity to the scwrypt-writer - scwrypts now publishes the package (scwrypts) to PyPi; this provides a simple way to invoke scwrypts from python-based environments as well as the entire scwrypts python library suite pip install scwrypts - scwrypts now publishes the package (scwrypts) to npm; this provides a simple way to invoke scwrypts from nodesjs environments npm install scwrypts --- Bug Fixes ------------------------------------------------------- - scwrypts runner prompts which use the zshbuiltin "read" now appropriately read input from tty, pipe, files, and user input - virtualenv refresh now loads and prepares the scwrypts virtual environments correctly --- Changes --------------------------------------------------------- - created the (-v, --log-level) scwrypts arguments as improvements of and replacements to the --verbose and --no-log flags - (-n) is now an alias for (--log-level 0) - (--no-log) is the same as (-n) for compatibility, but will be removed in 4.2 - zsh/lib/utils/io print functions now *interact with log-level* various log levels will now only display the appropriate console prints for the specified log level - zsh/lib/utils/io:INFO has been renamed to DEBUG to align with log-level output; please use DEBUG for debug messages and REMINDER for important user messages - created zsh/lib/utils/io:FZF_USER_INPUT as a *drop-in replacement* for the confusing FZF_HEAD and FZF_TAIL commands. Update by literally changing any instances of FZF_HEAD or FZF_TAIL with FZF_USER_INPUT - FZF_HEAD and FZF_TAIL will be removed in 4.2 - zsh/lib/utils/io:READ (and other zshbuiltin/read-based prompts) now accept a --force-user-input flag in case important checks should require an admin's approval. This flag will ensure that piped input and the `scwrypts -y` flag are ignored for the single prompt. - zsh/lib/utils/color has been updated to use color names which match the ANSI color names - zsh/hello-world has been reduced to a minimal example; this is to emphasize ease-of-use with v4 - zsh/sanity-check is a scwrypts/run testing helper and detailed starting reference (helpful since hello-world is now minimal) - various refactor, updates, and improvements to the scwrypts runner - migrated all zsh scwrypts and plugins to use v4 runner syntax - zsh - plugins/kubectl - plugins/ci - refactored py/lib into py/lib/scwrypts (PyPi)
127 lines
3.3 KiB
Bash
127 lines
3.3 KiB
Bash
#####################################################################
|
|
|
|
DEPENDENCIES+=()
|
|
REQUIRED_ENV+=()
|
|
|
|
use utils
|
|
|
|
#####################################################################
|
|
|
|
SCWRYPTS__SELECT_ENV() {
|
|
SCWRYPTS__GET_ENV_NAMES | FZF 'select an environment'
|
|
}
|
|
|
|
SCWRYPTS__SELECT_OR_CREATE_ENV() {
|
|
SCWRYPTS__GET_ENV_NAMES | FZF_USER_INPUT 'select / create an environment'
|
|
}
|
|
|
|
SCWRYPTS__GET_ENV_FILES() {
|
|
local NAME="$1"
|
|
|
|
local FILENAMES=$(
|
|
for GROUP in ${SCWRYPTS_GROUPS[@]}
|
|
do
|
|
echo "$SCWRYPTS_ENV_PATH/$GROUP/$NAME"
|
|
done
|
|
)
|
|
|
|
echo $FILENAMES | grep 'environments/scwrypts/'
|
|
echo $FILENAMES | grep -v 'environments/scwrypts/' | sort
|
|
|
|
SCWRYPTS__GET_ENV_NAMES | grep -q $NAME \
|
|
|| { ERROR "no environment '$NAME' exists"; return 1; }
|
|
}
|
|
|
|
SCWRYPTS__GET_ENV_FILE() {
|
|
local NAME="$1"
|
|
local GROUP="$2"
|
|
|
|
[ ! $GROUP ] && { ERROR 'must provide group'; return 1; }
|
|
|
|
echo "$SCWRYPTS_ENV_PATH/$GROUP/$NAME"
|
|
|
|
SCWRYPTS__GET_ENV_NAMES | grep -q $NAME \
|
|
|| { ERROR "no environment '$NAME' exists"; return 1; }
|
|
|
|
[ -f "$SCWRYPTS_ENV_PATH/$GROUP/$NAME" ] || {
|
|
mkdir -p "$SCWRYPTS_ENV_PATH/$GROUP"
|
|
touch "$SCWRYPTS_ENV_PATH/$GROUP/$NAME"
|
|
}
|
|
[ -f "$SCWRYPTS_ENV_PATH/$GROUP/$NAME" ] \
|
|
|| { ERROR "missing environment file for '$GROUP/$NAME'"; return 2; }
|
|
}
|
|
|
|
SCWRYPTS__GET_ENV_TEMPLATE_FILES() {
|
|
local GROUP
|
|
for GROUP in ${SCWRYPTS_GROUPS[@]}
|
|
do
|
|
eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template
|
|
done
|
|
}
|
|
|
|
SCWRYPTS__GET_ENV_NAMES() {
|
|
SCWRYPTS__INIT_ENVIRONMENTS || {
|
|
ERROR 'environment initialization error'
|
|
return 1
|
|
}
|
|
[ $REQUIRED_ENVIRONMENT_REGEX ] && {
|
|
ls "$SCWRYPTS_ENV_PATH/scwrypts" | grep "$REQUIRED_ENVIRONMENT_REGEX" | sort -r
|
|
} || {
|
|
ls "$SCWRYPTS_ENV_PATH/scwrypts" | sort -r
|
|
}
|
|
}
|
|
|
|
SCWRYPTS__INIT_ENVIRONMENTS() {
|
|
[ ! -d "$SCWRYPTS_ENV_PATH" ] && mkdir -p "$SCWRYPTS_ENV_PATH"
|
|
[[ $(ls "$SCWRYPTS_ENV_PATH" | wc -l) -gt 0 ]] && return 0
|
|
|
|
STATUS "initializing environments for scwrypts"
|
|
|
|
local BASIC_ENV
|
|
for BASIC_ENV in local dev prod
|
|
do
|
|
for GROUP in ${SCWRYPTS_GROUPS[@]}
|
|
do
|
|
mkdir -p "$SCWRYPTS_ENV_PATH/$GROUP"
|
|
GENERATE_TEMPLATE > "$SCWRYPTS_ENV_PATH/$GROUP/$BASIC_ENV"
|
|
done
|
|
done
|
|
}
|
|
|
|
#####################################################################
|
|
|
|
_SED() { sed --follow-symlinks $@; }
|
|
|
|
GENERATE_TEMPLATE() {
|
|
[ ! $GROUP ] && { ERROR 'must provide GROUP'; return 1; }
|
|
DIVIDER='#####################################################################'
|
|
HEADER='### scwrypts runtime configuration '
|
|
[[ GROUP =~ ^scwrypts$ ]] || HEADER="${HEADER}(group '$GROUP') "
|
|
printf "#!/bin/zsh\n$DIVIDER\n$HEADER%s\n$DIVIDER\n" "${DIVIDER:${#$(echo "$HEADER")}}"
|
|
|
|
local FILE CONTENT
|
|
local VARIABLE DESCRIPTION
|
|
FILE=$(eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template)
|
|
|
|
CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/')
|
|
|
|
while read DESCRIPTION_LINE
|
|
do
|
|
VARIABLE=$(echo $DESCRIPTION_LINE | sed 's/ \+| .*$//')
|
|
DESCRIPTION=$(echo $DESCRIPTION_LINE | sed 's/^.* | //')
|
|
[ ! $DESCRIPTION ] && continue
|
|
|
|
CONTENT=$(echo "$CONTENT" | sed "/^export $VARIABLE=/i #" | sed "/^export $VARIABLE=/i # $DESCRIPTION")
|
|
done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions")
|
|
|
|
echo "$CONTENT" | sed 's/^#$//'
|
|
}
|
|
|
|
GET_VARIABLE_NAMES() {
|
|
local FILE="$1"
|
|
grep '^export' "$FILE" \
|
|
| sed 's/^export //; s/=.*//' \
|
|
| grep -v '__[a-z]\+$' \
|
|
;
|
|
}
|