feat: consistent log prefix

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
Vladislav Doster 2023-12-24 06:10:21 -06:00
parent 956f4b764c
commit 5edd64db79
2 changed files with 57 additions and 54 deletions

View file

@ -231,7 +231,7 @@ if (( ${+ICE[sbin]} )) {
command chmod +x "$file.cmd" command chmod +x "$file.cmd"
continue continue
fi fi
.za-bgn-bin-or-src-function-body 0 \ .za-bgn-bin-or-src-function-body 0 \
"$fnam" \ "$fnam" \
"$target_binary" "$dir" "$set_gem_home" \ "$target_binary" "$dir" "$set_gem_home" \
@ -246,13 +246,13 @@ if (( ${+ICE[sbin]} )) {
(( !OPTS[opt_-q,--quiet] )) && \ (( !OPTS[opt_-q,--quiet] )) && \
if [[ -x $target_binary ]]; then if [[ -x $target_binary ]]; then
if [[ $hook == atclone-<-> || $ZINIT[annex-multi-flag:pull-active] -ge 2 ]] { if [[ $hook == atclone-<-> || $ZINIT[annex-multi-flag:pull-active] -ge 2 ]] {
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim and set +x on the %F{219}${target_binary:t}%F{154} binary%f" +zi-log "{m} {b}sbin{rst}: ${${${hook:#*atclone-<->}:+Re-c}:-C}reated {file}$fnam{rst} shim & set +x on the {file}${target_binary:t}{rst} binary"
} }
else else
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim %F{160}however the %F{219}${target_binary:t}%F{160} binary does not exist or failed to set +x on it%f" +zi-log "{m} {b}sbin{rst}: ${${${hook:#*atclone-<->}:+Re-c}:-C}reated {file}$fnam{rst} shim, but {file}${target_binary:t}{rst} binary does not exist or failed to set +x on it"
fi fi
else else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong creating the %F{219}$fnam%F{160} shim%f" +zi-log "{e} {b}sbin{rst}: Failed to create {file}$fnam{rst} shim"
fi fi
if ((use_1)); then if ((use_1)); then
(($#fnames-1)) && \ (($#fnames-1)) && \

View file

@ -1,82 +1,85 @@
# Copyright (c) 2019-2020 Sebastian Gniazdowski # Copyright (c) 2019-2020 Sebastian Gniazdowski
# License MIT # License MIT
emulate -RL zsh emulate -LR zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops setopt extendedglob noshortloops nullglob typesetsilent warncreateglobal
if [[ "$1" = plugin ]]; then
[[ "$1" = plugin ]] && \ local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6"
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" hook="$6" || \ else
local type="$1" url="$2" id_as="$3" dir="$4" hook="$5" local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5"
fi
local nl=$'\n'
# #
# sbin'' ice creation of shims (the name borrowed from rbenv) # sbin'' ice creation of shims (the name borrowed from rbenv)
# #
if (( ${+ICE[sbin]} )) { if (( ${+ICE[sbin]} )); then
local -a sbins srcdst local -a sbins=() srcdst=()
sbins=( ${(s.;.)ICE[sbin]} ) # sbins+=(${(s.;.)ICE2[sbin]})
sbins+=(${(s.;.)ICE[sbin]})
(( !$#sbins )) && sbins+=("")
local sbin local sbin
integer set_gem_home set_node_path set_virtualenv (
builtin cd -q "$dir" || return
( for sbin in $sbins; do
builtin cd -q "$dir" integer set_gem_home=0 set_node_path=0 set_virtualenv=0 set_cwd=0 use_all_null=0 use_err_null=0 use_out_null=0 use_1=0
for sbin ( $sbins "" ) { if [[ -z $sbin ]]; then
if [[ -z $sbin && ${#sbins} -eq 0 ]]; then
if [[ -f $dir/${id_as:t} ]]; then if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}" sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin" sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}" sbin="$dir/${url:t}"
elif [[ -f $dir/**/($id_as:t|$plugin)(#qN[1].) ]]; then
sbin=($dir/**/($id_as:t|$plugin)(Nnon.))
sbin=$sbin[1]
else else
local -a files local -a files
files=( $dir/*(*Nnon:t) ) files=($dir/**/*(*Nnon:t))
if (( ${#files} )); then if (( ${#files} )); then
sbin="${files[1]}" sbin="${files[1]}"
else else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f" +zi-log "{w} {b}bin-gem-node{rst}: The automatic-empty sbin ice didn't find any executable files%f"
break break
fi fi
fi fi
elif [[ -z $sbin ]]; then fi
srcdst=(${(@s.=>.)${(@s.→.)${(@s.->.)sbin}}})
srcdst=("${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}")
[[ ${srcdst[1]} = [1gnpcNEO]#g[1gnpcNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [1gnpcNEO]#n[1gnpcNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [1gnpcNEO]#p[1gnpcNEO]#:* ]] && set_virtualenv=1
[[ ${srcdst[1]} = [1gnpcNEO]#c[1gnpcNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [1gnpcNEO]#N[1gnpcNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [1gnpcNEO]#E[1gnpcNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [1gnpcNEO]#O[1gnpcNEO]#:* ]] && use_out_null=1
[[ ${srcdst[1]} = [1gnpcNEO]#1[1gnpcNEO]#:* ]] && use_1=1
srcdst[1]=${srcdst[1]#[a-zA-Z0-9]#:}
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames=()
local fname
if [[ $srcdst[1] != /* ]]; then
eval "fnames=( **/${srcdst[1]}(Nnon-.) )"
else
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
fi
if (( !${#fnames} )); then
+zi-log "{e} {b}bin-gem-node{rst}: The {ice}sbin{rst} ice ({glob}$sbin{rst}) did not match any files"
continue continue
fi fi
for fname in $fnames; do
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gnpcNEO]#g[gnpcNEO]#:* ]] && set_gem_home=1 || set_gem_home=0
[[ ${srcdst[1]} = [gnpcNEO]#n[gnpcNEO]#:* ]] && set_node_path=1 || set_node_path=0
[[ ${srcdst[1]} = [gnpcNEO]#p[gnpcNEO]#:* ]] && set_virtualenv=1 || set_virtualenv=0
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon-.) )"
for fname ( $fnames ) {
srcdst[1]="$fname" srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \ local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" fnam="${srcdst[2]:-${srcdst[1]:t}}"
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam" local file="$ZPFX/bin/$fnam"
command rm -f "$file"
if [[ -f $file ]]; then if [[ ! -e $file ]]; then
command rm -f "$file" (( !OPTS[opt_-q,--quiet] )) && +zi-log "{m} {b}sbin{rst}: Deleted {file}$fnam{rst} shim"
if [[ -f $file ]]; then
print -P -- "%F{38}bin-gem-node annex: %F{160}Couldn't remove the %F{220}$fnam%F{160} shim from \$ZPFX/bin (no write access to \$ZPFX/bin?)%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{154}Correctly removed the %F{220}$fnam%F{154} shim from \$ZPFX/bin%f" || \
fi
else else
print -P -- "%F{38}bin-gem-node annex: %F{160}The %F{220}$fnam%F{160} shim didn't exist in \$ZPFX/bin (or isn't a regular file)%f" +zi-log "{w} {b}sbin{rst}: {file}$fnam{rst} shim not found in \$ZPFX/bin"
fi fi
} done
} done
) )
} fi
# vim:ft=zsh:sw=4:sts=4:et # vim:ft=zsh:sw=4:sts=4:et