Skip to content

Commit

Permalink
v4.4.0
Browse files Browse the repository at this point in the history
=====================================================================

Increased non-scwrypts-runtime compatibility and improved clarity
in user environments after sourcing the scwrypts.plugin.zsh.

--- New Features -------------------------

- added experimental support for --output json
- added 'scwrypts --list-groups' to output the SCWRYPTS_GROUPS value
- added 'scwrypts --config' to be `eval`-ed in non-scwrypts-runtime zsh

--- Changes ------------------------------

- removed config variables which pertained to old scwrypts

- removed deprecated --no-log

- cleaned up environment requirements and improved import saftey for
  scwrypts.plugin.zsh; scwrypts is now *required* on $PATH in order to work

- refactored group configuration to match external group configuration
  (configuration now in scwrypts.scwrypts.zsh rather than zsh/lib/config.group.zsh)

- plugins/kubectl now forces an unalias of `f` (for fluxcd) on load

- the 'use' command now supports the '-c' short flag for ease of quick
  use

- upgraded max supported python version to 3.12; dropped support for
  python 3.9 (>3.10 required)

- remove old references to SCWRYPTS_ROOT in favour of SCWRYPTS_ROOT__scwrypts

- SCWRYPTS_LOG_LEVEL setting is now forwarded when using the SCWRYPTS__RUN
  meta execution function
  • Loading branch information
wrynegade committed May 9, 2024
1 parent 4146a0d commit 3fe01a7
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 137 deletions.
4 changes: 0 additions & 4 deletions .config/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export DISCORD__DEFAULT_AVATAR_URL=
export DISCORD__DEFAULT_CHANNEL_ID=
export DISCORD__DEFAULT_USERNAME=
export DISCORD__DEFAULT_WEBHOOK=
export I3__BORDER_PIXEL_SIZE=
export I3__DMENU_FONT_SIZE=
export I3__GLOBAL_FONT_SIZE=
export I3__MODEL_CONFIG=
export LINEAR__API_TOKEN=
export MEDIA_SYNC__S3_BUCKET
export MEDIA_SYNC__TARGETS
Expand Down
5 changes: 0 additions & 5 deletions .config/env.template.descriptions
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ DISCORD__DEFAULT_CHANNEL_ID |
DISCORD__DEFAULT_USERNAME |
DISCORD__DEFAULT_WEBHOOK |

I3__BORDER_PIXEL_SIZE | custom i3 configuration settings
I3__DMENU_FONT_SIZE |
I3__GLOBAL_FONT_SIZE |
I3__MODEL_CONFIG |

LINEAR__API_TOKEN | linear.app project management configuration

MEDIA_SYNC__S3_BUCKET | s3 bucket name and filesystem targets for media backups
Expand Down
3 changes: 1 addition & 2 deletions plugins/kubectl/driver/kubectl.driver.zsh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[[ $SCWRYPTS_KUBECTL_DRIVER_READY -eq 1 ]] && return 0

unalias k h >/dev/null 2>&1
unalias k h f >/dev/null 2>&1
k() { _SCWRYPTS_KUBECTL_DRIVER kubectl $@; }
h() { _SCWRYPTS_KUBECTL_DRIVER helm $@; }
f() { _SCWRYPTS_KUBECTL_DRIVER flux $@; }


_SCWRYPTS_KUBECTL_DRIVER() {
[ ! $SCWRYPTS_ENV ] && {
ERROR "must set SCWRYPTS_ENV in order to use '$(echo $CLI | head -c1)'"
Expand Down
2 changes: 1 addition & 1 deletion py/lib/scwrypts/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def getenv(name, required=True):
value = os_getenv(name, None)
value = os_getenv(f'{name}__override', os_getenv(name))

if required and not value:
raise MissingVariableError(name)
Expand Down
113 changes: 80 additions & 33 deletions scwrypts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/zsh
export EXECUTION_DIR=$(pwd)
export SCWRYPTS_RUNTIME_ID=$(uuidgen)
source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
#####################################################################
() {
Expand All @@ -21,6 +22,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
runtime
-y, --yes auto-accept all [yn] prompts through current scwrypt
-e, --env <env-name> set environment; overwrites SCWRYPTS_ENV
-n shorthand for "--log-level 0"
-v, --log-level [0-4] set incremental scwrypts log level to one of the following:
0 : only command output and critical failures; skips logfile
Expand All @@ -29,13 +31,19 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
3 : (default) include warning messages
4 : include debug messages
-o, --output specify output format; one of:
pretty (default)
json (experimental)
alternate commands
-h, --help display this message and exit
-l, --list print out command list and exit
--list-envs print out environment list and exit
--root print out SCWRYPTS_ROOT__scwrypts and exit
--update update scwrypts library to latest version
--version print out scwrypts version and exit
-h, --help display this message and exit
-l, --list print out command list and exit
--list-envs print out environment list and exit
--list-groups print out configured scwrypts groups and exit
--config "eval"-ed to enable config and "use" import in non-scwrypts environments
--root print out SCWRYPTS_ROOT__scwrypts and exit
--update update scwrypts library to latest version
--version print out scwrypts version and exit
patterns:
- a list of glob patterns to loose-match a scwrypt by name
Expand All @@ -56,8 +64,10 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42

[ ! $SCWRYPTS_LOG_LEVEL ] && local SCWRYPTS_LOG_LEVEL=3

local SHIFT_COUNT
while [[ $# -gt 0 ]]
do
SHIFT_COUNT=1
case $1 in
-[a-z][a-z]* )
VARSPLIT=$(echo "$1 " | sed 's/^\(-.\)\(.*\) /\1 -\2/')
Expand All @@ -81,6 +91,11 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
return 0
;;

--list-groups )
echo "${SCWRYPTS_GROUPS[@]}" | sed 's/\s\+/\n/g' | sort -u
return 0
;;

--version )
case $SCWRYPTS_INSTALLATION_TYPE in
manual ) echo "scwrypts $(GIT_SCWRYPTS describe --tags) (via GIT)" ;;
Expand All @@ -94,6 +109,13 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
return 0
;;

--config )
echo "source '$SCWRYPTS_ROOT__scwrypts/zsh/lib/import.driver.zsh'"
echo "CHECK_ENVIRONMENT --no-fail --no-usage"
echo "unset __SCWRYPT"
return 0
;;

--update )
case $SCWRYPTS_INSTALLATION_TYPE in
aur )
Expand All @@ -104,7 +126,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
;;

homebrew )
SCWRYPTS_LOG_LEVEL=3 REMINDER "This installation is managed by homebrew. Update me with 'brew update scwrypts'"
SCWRYPTS_LOG_LEVEL=3 REMINDER "This installation is managed by homebrew. Update me with 'brew update'"
;;

manual )
Expand Down Expand Up @@ -142,46 +164,52 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
### scwrypts filters #####################

-m | --name )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_NAME=$2
shift 1
;;

-g | --group )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_GROUP=$2
shift 1
;;

-t | --type )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_TYPE=$2
shift 1
;;

### runtime settings #####################

-y | --yes ) export __SCWRYPTS_YES=1 ;;

-n | --no-log )
SCWRYPTS_LOG_LEVEL=0
[[ $1 =~ ^--no-log$ ]] && WARNING 'the --no-log flag is deprecated and will be removed in scwrypts v4.2'
;;
-n ) SCWRYPTS_LOG_LEVEL=0 ;;

-v | --log-level )
((SHIFT_COUNT+=1))
[[ $2 =~ ^[0-4]$ ]] || ERROR "invalid setting for log-level '$2'"
SCWRYPTS_LOG_LEVEL=$2
shift 1
;;

-o | --output )
((SHIFT_COUNT+=1))
export SCWRYPTS_OUTPUT_FORMAT=$2
case $SCWRYPTS_OUTPUT_FORMAT in
pretty | json ) ;;
* ) ERROR "unsupported format '$SCWRYPTS_OUTPUT_FORMAT'" ;;
esac
;;

-e | --env )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; }

[ $ENV_NAME ] && DEBUG 'overwriting session environment'

ENV_NAME="$2"
STATUS "using CLI environment '$ENV_NAME'"
shift 1
;;

##########################################
Expand All @@ -190,9 +218,11 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
--* ) ERROR "unrecognized argument '$1'" ;;
* ) SEARCH_PATTERNS+=($1) ;;
esac
shift 1
shift $SHIFT_COUNT
done

[ $SCWRYPTS_OUTPUT_FORMAT ] || export SCWRYPTS_OUTPUT_FORMAT=pretty

[ $SEARCH_NAME ] && {
[ $SEARCH_TYPE ] || ERROR '--name requires --type argument'
[ $SEARCH_GROUP ] || ERROR '--name requires --group argument'
Expand Down Expand Up @@ -384,25 +414,42 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
[[ $SCWRYPT_NAME =~ interactive ]] && RUN_MODE=interactive

local HEADER FOOTER

[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && {
HEADER=$(
echo "
=====================================================================
script : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME
run at : $(date)
config : $ENV_NAME
log level : $SCWRYPTS_LOG_LEVEL
\\033[1;33m--- SCWRYPT BEGIN ---------------------------------------------------\\033[0m
" | sed 's/^\s\+//; 1d'
)

FOOTER="\\033[1;33m--- SCWRYPT END ---------------------------------------------------\\033[0m"
case $SCWRYPTS_OUTPUT_FORMAT in
pretty )
HEADER=$(
echo "
=====================================================================
scwrypt : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME
run at : $(date)
config : $ENV_NAME
log level : $SCWRYPTS_LOG_LEVEL
\\033[1;33m--- SCWRYPT BEGIN ---------------------------------------------------\\033[0m
" | sed 's/^\s\+//; 1d'
)

FOOTER="\\033[1;33m--- SCWRYPT END ---------------------------------------------------\\033[0m"
;;
json )
HEADER=$(echo '{}' | jq -c ".
| .timestamp = \"$(date +%s)\"
| .runtime = \"$SCWRYPTS_RUNTIME_ID\"
| .scwrypt = \"start of $SCWRYPT_NAME $SCWRYPT_GROUP $SCWRYPT_TYPE\"
| .config = \"$ENV_NAME\"
| .logLevel = \"$SCWRYPTS_LOG_LEVEL\"
| .subscwrypt = $SUBSCWRYPT
")
;;
esac
}

[[ $SUBSCWRYPT -eq 0 ]] || {
HEADER="\\033[0;33m--- ($SUBSCWRYPT) BEGIN $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
FOOTER="\\033[0;33m--- ($SUBSCWRYPT) END $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
case $SCWRYPTS_OUTPUT_FORMAT in
pretty )
HEADER="\\033[0;33m--- ($SUBSCWRYPT) BEGIN $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
FOOTER="\\033[0;33m--- ($SUBSCWRYPT) END $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
;;
esac
}

#####################################################################
Expand Down Expand Up @@ -433,5 +480,5 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
&& echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m"

return $EXIT_CODE
} 2>&1 | tee --append "$LOGFILE"
} | tee --append "$LOGFILE"
} $@
Loading

0 comments on commit 3fe01a7

Please sign in to comment.