Skip to content

Commit

Permalink
Format case statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghosind committed Feb 23, 2024
1 parent b888405 commit eb90458
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
10 changes: 5 additions & 5 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ _dvm_completion() {
command="${COMP_WORDS[1]}"

case "$command" in
doctor)
"doctor")
_dvm_add_exclusive_option "--fix"
;;
install)
"install")
if [[ ${cur} == -* ]]
then
_dvm_add_install_option
fi
;;
use|uninstall|which)
"use"|"uninstall"|"which")
if ! _dvm_has_non_option_parameter
then
if [ "$command" = "which" ] && _dvm_has_active_version
Expand All @@ -147,7 +147,7 @@ _dvm_completion() {
_dvm_add_aliases_to_opts
fi
;;
run)
"run")
if _dvm_has_non_option_parameter
then
COMPREPLY=( "$(compgen -W "${opts}" -- "${cur}")" )
Expand All @@ -157,7 +157,7 @@ _dvm_completion() {
_dvm_add_versions_to_opts
_dvm_add_aliases_to_opts
;;
unalias)
"unalias")
if [ "$COMP_CWORD" == 2 ] || ! _dvm_has_non_option_parameter
then
_dvm_add_aliases_to_opts
Expand Down
57 changes: 30 additions & 27 deletions dvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export DVM_VERSION="v0.8.2"

# Gets user profile file path by the shell.
dvm_get_profile_file() {
case ${SHELL##*/} in
bash)
case "${SHELL##*/}" in
"bash")
DVM_PROFILE_FILE="$HOME/.bashrc"
;;
zsh)
"zsh")
DVM_PROFILE_FILE="$HOME/.zshrc"
;;
*)
Expand Down Expand Up @@ -90,17 +90,20 @@ export DVM_VERSION="v0.8.2"
while [ "$#" -gt "0" ]
do
case "$1" in
-q|--quiet)
"-q"|"--quiet")
DVM_QUIET_MODE=true
;;
--color)
"--color")
DVM_COLOR_MODE=true
;;
--no-color)
"--no-color")
DVM_COLOR_MODE=false
;;
--verbose)
"--verbose")
DVM_VERBOSE_MODE=true
;;
*)
;;
esac

shift
Expand Down Expand Up @@ -1608,10 +1611,10 @@ export DVM_VERSION="v0.8.2"
local request_url

case "$DVM_SOURCE" in
gitee)
"gitee")
request_url="https://gitee.com/api/v5/repos/ghosind/dvm/releases/latest"
;;
github|*)
"github"|*)
request_url="https://api.github.com/repos/ghosind/dvm/releases/latest"
;;
esac
Expand Down Expand Up @@ -1727,28 +1730,28 @@ dvm() {

dvm_parse_options "$@"

case $1 in
alias)
case "$1" in
"alias")
shift

dvm_set_alias "$@"

;;
clean)
"clean")
# remove all download packages.
dvm_clean_download_cache

;;
current)
"current")
# get the current version
dvm_print_current_version

;;
deactivate)
"deactivate")
dvm_deactivate

;;
doctor)
"doctor")
local mode

shift
Expand Down Expand Up @@ -1777,7 +1780,7 @@ dvm() {
dvm_scan_and_fix_versions "$mode"

;;
install | i)
"install"|"i")
# install the specified version
shift

Expand Down Expand Up @@ -1809,7 +1812,7 @@ dvm() {
dvm_install_version "$version"

;;
list | ls)
"list"|"ls")
# list all local versions
dvm_get_current_version

Expand All @@ -1818,12 +1821,12 @@ dvm() {
dvm_list_aliases

;;
list-remote | ls-remote)
"list-remote"|"ls-remote")
# list all remote versions
dvm_list_remote_versions

;;
purge)
"purge")
if ! dvm_confirm_with_prompt "Do you want to remove DVM from your computer?"
then
return
Expand All @@ -1837,7 +1840,7 @@ dvm() {
dvm_purge_dvm

;;
run)
"run")
shift

dvm_get_version "$@"
Expand Down Expand Up @@ -1865,7 +1868,7 @@ dvm() {
dvm_run_with_version "$@"

;;
which)
"which")
shift

dvm_get_version "$@"
Expand All @@ -1880,13 +1883,13 @@ dvm() {
dvm_locate_version "$@"

;;
unalias)
"unalias")
shift

dvm_rm_alias "$@"

;;
uninstall)
"uninstall")
# uninstall the specified version
shift

Expand All @@ -1901,7 +1904,7 @@ dvm() {
dvm_uninstall_version "$DVM_TARGET_VERSION"

;;
upgrade)
"upgrade")
if ! dvm_get_dvm_latest_version
then
return
Expand All @@ -1917,19 +1920,19 @@ dvm() {
dvm_update_dvm

;;
use)
"use")
# change current version to specified version
shift

dvm_use_version "$@"

;;
help|--help|-h)
"help"|"--help"|"-h")
# print help
dvm_print_help

;;
--version)
"--version")
# print dvm version
dvm_print "$DVM_VERSION"

Expand Down
20 changes: 10 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ dvm_get_latest_version() {
local response

case "$DVM_SOURCE" in
gitee)
"gitee")
request_url="https://gitee.com/api/v5/repos/ghosind/dvm/releases/latest"
;;
github|*)
"github"|*)
request_url="https://api.github.com/repos/ghosind/dvm/releases/latest"
;;
esac
Expand All @@ -68,11 +68,11 @@ dvm_get_latest_version() {
}

dvm_get_profile_file() {
case ${SHELL##*/} in
bash)
case "${SHELL##*/}" in
"bash")
DVM_PROFILE_FILE="$HOME/.bashrc"
;;
zsh)
"zsh")
DVM_PROFILE_FILE="$HOME/.zshrc"
;;
*)
Expand Down Expand Up @@ -111,10 +111,10 @@ dvm_install_latest_version() {
local cmd

case "$DVM_SOURCE" in
gitee)
"gitee")
git_url="https://gitee.com/ghosind/dvm.git"
;;
github|*)
"github"|*)
git_url="https://github.com/ghosind/dvm.git"
;;
esac
Expand Down Expand Up @@ -158,19 +158,19 @@ dvm_set_default
while getopts "hr:d:" opt
do
case "$opt" in
h)
"h")
dvm_print_help
exit 0
;;
r)
"r")
if [ "$OPTARG" != "github" ] && [ "$OPTARG" != "gitee" ]
then
dvm_print_help
exit 1
fi
DVM_SOURCE="$OPTARG"
;;
d)
"d")
if [ -z "$OPTARG" ]
then
dvm_print_help
Expand Down

0 comments on commit eb90458

Please sign in to comment.