feat(CLI): add omz changelog command

This commit is contained in:
Marc Cornellà 2020-11-04 11:35:01 +01:00
parent eeab4e5186
commit 7712da89ee

View file

@ -20,53 +20,43 @@ function omz {
} }
function _omz { function _omz {
local -a cmds subcmds local -a cmds subcmds
cmds=( cmds=(
'help:Usage information' 'changelog:Print the changelog'
'plugin:Commands for Oh My Zsh plugins management' 'help:Usage information'
'pr:Commands for Oh My Zsh Pull Requests management' 'plugin:Manage plugins'
'theme:Commands for Oh My Zsh themes management' 'pr:Manage Oh My Zsh Pull Requests'
'update:Update Oh My Zsh' 'theme:Manage themes'
) 'update:Update Oh My Zsh'
)
if (( CURRENT == 2 )); then if (( CURRENT == 2 )); then
_describe 'command' cmds _describe 'command' cmds
elif (( CURRENT == 3 )); then elif (( CURRENT == 3 )); then
case "$words[2]" in case "$words[2]" in
plugin) subcmds=('list:List plugins') changelog) local -a refs
_describe 'command' subcmds ;; refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches') _describe 'command' refs ;;
_describe 'command' subcmds ;; plugin) subcmds=('list:List plugins')
theme) subcmds=('use:Load a theme' 'list:List themes') _describe 'command' subcmds ;;
_describe 'command' subcmds ;; pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches')
esac _describe 'command' subcmds ;;
elif (( CURRENT == 4 )); then theme) subcmds=('use:Load a theme' 'list:List themes')
case "$words[2]::$words[3]" in _describe 'command' subcmds ;;
theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \ esac
"$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;; elif (( CURRENT == 4 )); then
esac case "$words[2]::$words[3]" in
fi theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \
"$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;;
esac
fi
return 0 return 0
} }
compdef _omz omz compdef _omz omz
## Utility functions
function _omz::help {
cat <<EOF
Usage: omz <command> [options]
Available commands:
help Print this help message
plugin <command> Manage plugins
pr <command> Manage Oh My Zsh Pull Requests
theme <command> Manage themes
update Update Oh My Zsh
EOF
}
function _omz::confirm { function _omz::confirm {
# If question supplied, ask it before reading the answer # If question supplied, ask it before reading the answer
@ -111,6 +101,41 @@ function _omz::log {
esac >&2 esac >&2
} }
## User-facing commands
function _omz::help {
cat <<EOF
Usage: omz <command> [options]
Available commands:
help Print this help message
changelog Print the changelog
plugin <command> Manage plugins
pr <command> Manage Oh My Zsh Pull Requests
theme <command> Manage themes
update Update Oh My Zsh
EOF
}
function _omz::changelog {
local version=${1:-HEAD} format=${3:-"--text"}
if ! command git -C "$ZSH" show-ref --verify refs/heads/$version &>/dev/null && \
! command git -C "$ZSH" show-ref --verify refs/tags/$version &>/dev/null && \
! command git -C "$ZSH" rev-parse --verify "${version}^{commit}" &>/dev/null; then
cat <<EOF
Usage: omz changelog [version]
NOTE: <version> must be a valid branch, tag or commit.
EOF
return 1
fi
"$ZSH/tools/changelog.sh" "$version" "${2:-}" "$format"
}
function _omz::plugin { function _omz::plugin {
(( $# > 0 && $+functions[_omz::plugin::$1] )) || { (( $# > 0 && $+functions[_omz::plugin::$1] )) || {
cat <<EOF cat <<EOF