Skip to content

Commit 85a0721

Browse files
alberti42vladdoster
andcommitted
refactor: implemented parsing of options for self-update using .zinit-parse-opts; extended number of supports variants, options
Follows suggestions from #762 (review) Co-authored-by: vladislav doster <mvdoster@gmail.com>
1 parent 726f94f commit 85a0721

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

_zinit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ _zinit_run(){
273273
} # ]]]
274274
# FUNCTION: _zinit_self_update [[[
275275
_zinit_self_update(){
276+
_arguments -A \
277+
'(-h --help)'{-h,--help}'[Show this help message]' \
278+
'(-q --quiet)'{-q,--quiet}'[Turn off messages from the operation]' \
279+
&& ret=0
276280
} # ]]]
277281
# FUNCTION: _zinit_snippet [[[
278282
_zinit_snippet(){

zinit-autoload.zsh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,13 +1966,11 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
19661966
#
19671967
# $1 - Absolute path to Git repository"
19681968
.zi-check-for-git-changes() {
1969-
local quiet=0
1970-
[[ $1 = -q ]] && { quiet=1; shift; }
19711969
+zi-log "{dbg} checking $1"
19721970
if command git -C "$1" rev-parse --is-inside-work-tree &> /dev/null; then
19731971
if command git -C "$1" rev-parse --abbrev-ref @'{u}' &> /dev/null; then
19741972
REPLY=$(command git -C "$1" rev-parse --abbrev-ref HEAD)
1975-
if (( ! quiet )); then
1973+
if (( ! OPTS[opt_-q,--quiet] )); then
19761974
local nl=$'\n'
19771975
+zi-log -n "{pre}[self-update]{info} fetching latest changes from {obj}$REPLY{info} branch$nl{rst}"
19781976
fi
@@ -1983,7 +1981,7 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
19831981
return 0
19841982
fi
19851983
fi
1986-
(( ! quiet )) && +zi-log "{m} Already up to date"
1984+
(( ! OPTS[opt_-q,--quiet] )) && +zi-log "{m} Already up to date"
19871985
return 1
19881986
fi
19891987
} # ]]]
@@ -1993,11 +1991,9 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
19931991
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
19941992
setopt extendedglob typesetsilent warncreateglobal
19951993

1996-
if .zi-check-for-git-changes ${1:+"$1"} "$ZINIT[BIN_DIR]"; then
1994+
if .zi-check-for-git-changes "$ZINIT[BIN_DIR]"; then
19971995
# Store branch name resolved by .zi-check-for-git-changes via $REPLY
19981996
local current_branch=$REPLY
1999-
2000-
[[ $1 = -q ]] && +zi-log "{pre}[self-update]{info} updating zinit repository{msg2}" \
20011997

20021998
local nl=$'\n' escape=$'\x1b['
20031999
# Warn if user is not on main (requested by maintainer)
@@ -2025,21 +2021,21 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
20252021
builtin print
20262022
fi
20272023
# Do not use hardcoded 'origin main' to let git use the configured upstream
2028-
if [[ $1 != -q ]] {
2024+
if (( ! OPTS[opt_-q,--quiet] )) {
20292025
command git pull --no-stat --ff-only
20302026
} else {
20312027
command git pull --no-stat --quiet --ff-only
20322028
}
20332029
)
2034-
if [[ $1 != -q ]] {
2030+
if (( ! OPTS[opt_-q,--quiet] )) {
20352031
+zi-log "{pre}[self-update]{info} compiling zinit via {obj}zcompile{rst}"
20362032
}
20372033
command rm -f $ZINIT[BIN_DIR]/*.zwc(DN)
20382034
zcompile -U $ZINIT[BIN_DIR]/zinit.zsh
20392035
zcompile -U $ZINIT[BIN_DIR]/zinit-{'side','install','autoload','additional'}.zsh
20402036
zcompile -U $ZINIT[BIN_DIR]/share/git-process-output.zsh
20412037
# Load for the current session
2042-
[[ $1 != -q ]] && +zi-log "{pre}[self-update]{info} reloading zinit for the current session{rst}"
2038+
(( ! OPTS[opt_-q,--quiet] )) && +zi-log "{pre}[self-update]{info} reloading zinit for the current session{rst}"
20432039

20442040
# +zi-log "{pre}[self-update]{info} resetting zinit repository via{rst}: {cmd}${ICE[reset]:-git reset --hard HEAD}{rst}"
20452041
source $ZINIT[BIN_DIR]/zinit.zsh
@@ -3402,7 +3398,9 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
34023398

34033399
local -F2 SECONDS=0
34043400

3405-
.zinit-self-update -q
3401+
local -A OPTS
3402+
OPTS[opt_-q,--quiet]=1
3403+
.zinit-self-update
34063404

34073405
[[ $2 = restart ]] && \
34083406
+zi-log "{msg2}Restarting the update with the new codebase loaded.{rst}"$'\n'

zinit.zsh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,13 +2623,14 @@ zinit() {
26232623
light "--help|-b|-h"
26242624
snippet "--command|--force|--help|-f|-h|-x"
26252625
times "--help|-h|-m|-s"
2626+
self-update "--help|--quiet|-h|-q"
26262627
unload "--help|--quiet|-h|-q"
26272628
update "--all|--help|--no-pager|--parallel|--plugins|--quiet|--reset|--snippets|--urge|--verbose|-L|-a|-h|-n|-p|-q|-r|-s|-u|-v"
26282629
version ""
26292630
)
26302631

26312632
cmd="$1"
2632-
if [[ $cmd == (times|unload|env-whitelist|update|snippet|load|light|cdreplay|cdclear) ]]; then
2633+
if [[ $cmd == (times|unload|env-whitelist|update|snippet|load|light|cdreplay|cdclear|self-update) ]]; then
26332634
if (( $@[(I)-*] || OPTS[opt_-h,--help] )); then
26342635
.zinit-parse-opts "$cmd" "$@"
26352636
if (( OPTS[opt_-h,--help] )); then
@@ -2950,7 +2951,8 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice
29502951
.zinit-show-times "${@[2-correct,-1]}"
29512952
;;
29522953
(self-update)
2953-
.zinit-self-update "${@[2-correct,-1]}"
2954+
.zinit-parse-opts "self-update" "$@"
2955+
.zinit-self-update
29542956
;;
29552957
(unload)
29562958
(( ${+functions[.zinit-unload]} )) || builtin source "${ZINIT[BIN_DIR]}/zinit-autoload.zsh" || return 1

0 commit comments

Comments
 (0)