mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Fix many shellcheck issues; ignore a few others
This commit is contained in:
parent
bf60c7f3ac
commit
808a8d48b7
101
bin/asdf
101
bin/asdf
@ -1,95 +1,114 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $(dirname $(dirname $0))/lib/utils.sh
|
||||
# shellcheck source=lib/utils.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/utils.sh"
|
||||
|
||||
source $(dirname $(dirname $0))/lib/commands/help.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/update.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/install.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/uninstall.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/current.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/where.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/which.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/version_commands.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/list.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/list-all.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/reshim.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-add.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-list.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-list-all.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
|
||||
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-push.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-test.sh
|
||||
# shellcheck source=lib/commands/help.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/help.sh"
|
||||
# shellcheck source=lib/commands/update.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/update.sh"
|
||||
# shellcheck source=lib/commands/install.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/install.sh"
|
||||
# shellcheck source=lib/commands/uninstall.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/uninstall.sh"
|
||||
# shellcheck source=lib/commands/current.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/current.sh"
|
||||
# shellcheck source=lib/commands/where.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/where.sh"
|
||||
# shellcheck source=lib/commands/which.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/which.sh"
|
||||
# shellcheck source=lib/commands/version_commands.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/version_commands.sh"
|
||||
# shellcheck source=lib/commands/list.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/list.sh"
|
||||
# shellcheck source=lib/commands/list-all.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/list-all.sh"
|
||||
# shellcheck source=lib/commands/reshim.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/reshim.sh"
|
||||
# shellcheck source=lib/commands/plugin-add.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-add.sh"
|
||||
# shellcheck source=lib/commands/plugin-list.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list.sh"
|
||||
# shellcheck source=lib/commands/plugin-list-all.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list-all.sh"
|
||||
# shellcheck source=lib/commands/plugin-update.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-update.sh"
|
||||
# shellcheck source=lib/commands/plugin-remove.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-remove.sh"
|
||||
|
||||
# shellcheck source=lib/commands/plugin-push.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-push.sh"
|
||||
# shellcheck source=lib/commands/plugin-test.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-test.sh"
|
||||
|
||||
# shellcheck disable=SC2124
|
||||
callback_args="${@:2}"
|
||||
|
||||
case $1 in
|
||||
|
||||
"--version")
|
||||
asdf_version $callback_args;;
|
||||
asdf_version "$callback_args";;
|
||||
|
||||
"help")
|
||||
help_command $callback_args;;
|
||||
help_command "$callback_args";;
|
||||
|
||||
"update")
|
||||
update_command $callback_args;;
|
||||
update_command "$callback_args";;
|
||||
|
||||
"install")
|
||||
install_command $callback_args;;
|
||||
install_command "$callback_args";;
|
||||
|
||||
"uninstall")
|
||||
uninstall_command $callback_args;;
|
||||
uninstall_command "$callback_args";;
|
||||
|
||||
"current")
|
||||
current_command $callback_args;;
|
||||
current_command "$callback_args";;
|
||||
|
||||
"where")
|
||||
where_command $callback_args;;
|
||||
where_command "$callback_args";;
|
||||
|
||||
"which")
|
||||
which_command $callback_args;;
|
||||
which_command "$callback_args";;
|
||||
|
||||
"local")
|
||||
local_command $callback_args;;
|
||||
local_command "$callback_args";;
|
||||
|
||||
"global")
|
||||
global_command $callback_args;;
|
||||
global_command "$callback_args";;
|
||||
|
||||
"list")
|
||||
list_command $callback_args;;
|
||||
list_command "$callback_args";;
|
||||
|
||||
"list-all")
|
||||
list_all_command $callback_args;;
|
||||
list_all_command "$callback_args";;
|
||||
|
||||
"shim")
|
||||
shim_command $callback_args;;
|
||||
shim_command "$callback_args";;
|
||||
|
||||
"reshim")
|
||||
reshim_command $callback_args;;
|
||||
reshim_command "$callback_args";;
|
||||
|
||||
"plugin-add")
|
||||
plugin_add_command $callback_args;;
|
||||
plugin_add_command "$callback_args";;
|
||||
|
||||
"plugin-list")
|
||||
plugin_list_command $callback_args;;
|
||||
plugin_list_command "$callback_args";;
|
||||
|
||||
"plugin-list-all")
|
||||
plugin_list_all_command $callback_args;;
|
||||
plugin_list_all_command "$callback_args";;
|
||||
|
||||
"plugin-update")
|
||||
plugin_update_command $callback_args;;
|
||||
plugin_update_command "$callback_args";;
|
||||
|
||||
"plugin-remove")
|
||||
plugin_remove_command $callback_args;;
|
||||
plugin_remove_command "$callback_args";;
|
||||
|
||||
# Undocumented commands for development
|
||||
"plugin-push")
|
||||
plugin_push_command $callback_args;;
|
||||
plugin_push_command "$callback_args";;
|
||||
|
||||
"plugin-test")
|
||||
plugin_test_command $callback_args;;
|
||||
plugin_test_command "$callback_args";;
|
||||
|
||||
*)
|
||||
help_command
|
||||
|
@ -1,47 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $(dirname $(dirname $(dirname $0)))/lib/utils.sh
|
||||
# shellcheck source=lib/utils.sh
|
||||
source "$(dirname "$(dirname "$(dirname "$0")")")/lib/utils.sh"
|
||||
|
||||
plugin_name=$1
|
||||
executable_path=$2
|
||||
|
||||
plugin_path=$(get_plugin_path $plugin_name)
|
||||
check_if_plugin_exists $plugin_name
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
|
||||
full_version=$(get_preset_version_for $plugin_name)
|
||||
full_version=$(get_preset_version_for "$plugin_name")
|
||||
|
||||
if [ "$full_version" == "" ]; then
|
||||
echo "No version set for ${plugin_name}"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2162
|
||||
IFS=' ' read -a versions <<< "$full_version"
|
||||
|
||||
for version in "${versions[@]}"; do
|
||||
install_path=$(find_install_path $plugin_name $version)
|
||||
install_path=$(find_install_path "$plugin_name" "$version")
|
||||
|
||||
if [ $version != "system" ] && [ ! -d "$install_path" ]; then
|
||||
if [ "$version" != "system" ] && [ ! -d "$install_path" ]; then
|
||||
echo "$plugin_name $version not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
full_executable_path=$(get_executable_path $plugin_name $version $executable_path)
|
||||
if full_executable_path=$(get_executable_path "$plugin_name" "$version" "$executable_path"); then
|
||||
if [ -f "$full_executable_path" ]; then
|
||||
if [ -f "${plugin_path}/bin/exec-env" ]; then
|
||||
export ASDF_INSTALL_TYPE=$install_type
|
||||
export ASDF_INSTALL_VERSION=$version
|
||||
export ASDF_INSTALL_PATH=$install_path
|
||||
|
||||
if [ $? -eq 0 -a -f "$full_executable_path" ]; then
|
||||
if [ -f ${plugin_path}/bin/exec-env ]; then
|
||||
export ASDF_INSTALL_TYPE=$install_type
|
||||
export ASDF_INSTALL_VERSION=$version
|
||||
export ASDF_INSTALL_PATH=$install_path
|
||||
source "${plugin_path}/bin/exec-env"
|
||||
|
||||
source ${plugin_path}/bin/exec-env
|
||||
# unset everything, we don't want to pollute
|
||||
unset ASDF_INSTALL_TYPE
|
||||
unset ASDF_INSTALL_VERSION
|
||||
unset ASDF_INSTALL_PATH
|
||||
fi
|
||||
|
||||
# unset everything, we don't want to pollute
|
||||
unset ASDF_INSTALL_TYPE
|
||||
unset ASDF_INSTALL_VERSION
|
||||
unset ASDF_INSTALL_PATH
|
||||
exec "$full_executable_path" "${@:3}"
|
||||
fi
|
||||
|
||||
exec $full_executable_path "${@:3}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -1,39 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
_asdf () {
|
||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local cmd=${COMP_WORDS[1]}
|
||||
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local plugins=$(asdf plugin-list | tr '\n' ' ')
|
||||
local cur
|
||||
cur=${COMP_WORDS[COMP_CWORD]}
|
||||
local cmd
|
||||
cmd=${COMP_WORDS[1]}
|
||||
local prev
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local plugins
|
||||
plugins=$(asdf plugin-list | tr '\n' ' ')
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
case "$cmd" in
|
||||
plugin-update)
|
||||
COMPREPLY=($(compgen -W "$plugins --all" -- $cur))
|
||||
COMPREPLY=($(compgen -W "$plugins --all" -- "$cur"))
|
||||
;;
|
||||
plugin-remove|current|list|list-all)
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
|
||||
;;
|
||||
install)
|
||||
if [[ "$plugins" == *"$prev"* ]] ; then
|
||||
local versions=$(asdf list-all $prev)
|
||||
COMPREPLY=($(compgen -W "$versions" -- $cur))
|
||||
local versions
|
||||
versions=$(asdf list-all "$prev")
|
||||
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
|
||||
fi
|
||||
;;
|
||||
uninstall|where|reshim|local|global)
|
||||
if [[ "$plugins" == *"$prev"* ]] ; then
|
||||
local versions=$(asdf list $prev)
|
||||
COMPREPLY=($(compgen -W "$versions" -- $cur))
|
||||
local versions
|
||||
versions=$(asdf list "$prev")
|
||||
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall update current where which list list-all local global reshim'
|
||||
COMPREPLY=($(compgen -W "$cmds" -- $cur))
|
||||
COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
|
||||
;;
|
||||
esac
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_current_command() {
|
||||
local plugin_name=$1
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
help_command () {
|
||||
echo "version: $(asdf_version)"
|
||||
echo ""
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
handle_failure() {
|
||||
local install_path="$1"
|
||||
rm -rf "$install_path"
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
list_all_command() {
|
||||
local plugin_name=$1
|
||||
local plugin_path=$(get_plugin_path $plugin_name)
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
list_command() {
|
||||
local plugin_name=$1
|
||||
check_if_plugin_exists $plugin_name
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_add_command() {
|
||||
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
||||
display_error "usage: asdf plugin-add <name> [<git-url>]"
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_list_command() {
|
||||
local plugins_path=$(get_plugin_path)
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_push_command() {
|
||||
local plugin_name=$1
|
||||
if [ "$plugin_name" = "--all" ]; then
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_remove_command() {
|
||||
local plugin_name=$1
|
||||
check_if_plugin_exists $plugin_name
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
fail_test() {
|
||||
echo "FAILED: $1"
|
||||
rm -rf $ASDF_DIR
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plugin_update_command() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
display_error "usage: asdf plugin-update {<name> | --all}"
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
shim_command() {
|
||||
local plugin_name=$1
|
||||
local executable_path=$2
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
uninstall_command() {
|
||||
local plugin_name=$1
|
||||
local full_version=$2
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
update_command() {
|
||||
local update_to_head=$1
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
version_command() {
|
||||
local cmd=$1
|
||||
local plugin=$2
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
where_command() {
|
||||
local plugin_name=$1
|
||||
local full_version=$2
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
current_version() {
|
||||
local plugin_name=$1
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# We shouldn't rely on the user's grep settings to be correct. If we set these
|
||||
# here anytime asdf invokes grep it will be invoked with these options
|
||||
GREP_OPTIONS="--color=never"
|
||||
@ -12,7 +14,7 @@ asdf_version() {
|
||||
}
|
||||
|
||||
asdf_dir() {
|
||||
if [ -z $ASDF_DIR ]; then
|
||||
if [ -z "$ASDF_DIR" ]; then
|
||||
local current_script_path=${BASH_SOURCE[0]}
|
||||
export ASDF_DIR=$(cd $(dirname $(dirname $current_script_path)); echo $(pwd))
|
||||
fi
|
||||
@ -24,9 +26,9 @@ get_install_path() {
|
||||
local plugin=$1
|
||||
local install_type=$2
|
||||
local version=$3
|
||||
mkdir -p $(asdf_dir)/installs/${plugin}
|
||||
mkdir -p "$(asdf_dir)/installs/${plugin}"
|
||||
|
||||
if [ $install_type = "version" ]
|
||||
if [ "$install_type" = "version" ]
|
||||
then
|
||||
echo $(asdf_dir)/installs/${plugin}/${version}
|
||||
else
|
||||
|
@ -4,9 +4,9 @@ get_legacy_version() {
|
||||
current_directory=$1
|
||||
version_file="$current_directory/.dummy-version"
|
||||
|
||||
if [ -f $version_file ]; then
|
||||
cat $version_file
|
||||
if [ -f "$version_file" ]; then
|
||||
cat "$version_file"
|
||||
fi
|
||||
}
|
||||
|
||||
get_legacy_version $1
|
||||
get_legacy_version "$1"
|
||||
|
12
test/fixtures/dummy_plugin/bin/install
vendored
12
test/fixtures/dummy_plugin/bin/install
vendored
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
mkdir -p $ASDF_INSTALL_PATH
|
||||
env > $ASDF_INSTALL_PATH/env
|
||||
echo $ASDF_INSTALL_VERSION > $ASDF_INSTALL_PATH/version
|
||||
mkdir -p "$ASDF_INSTALL_PATH"
|
||||
env > "$ASDF_INSTALL_PATH/env"
|
||||
echo "$ASDF_INSTALL_VERSION" > "$ASDF_INSTALL_PATH/version"
|
||||
|
||||
# create the dummy executable
|
||||
mkdir -p $ASDF_INSTALL_PATH/bin
|
||||
cat <<EOF > $ASDF_INSTALL_PATH/bin/dummy
|
||||
mkdir -p "$ASDF_INSTALL_PATH/bin"
|
||||
cat <<EOF > "$ASDF_INSTALL_PATH/bin/dummy"
|
||||
echo This is Dummy ${ASDF_INSTALL_VERSION}! \$2 \$1
|
||||
EOF
|
||||
chmod +x $ASDF_INSTALL_PATH/bin/dummy
|
||||
chmod +x "$ASDF_INSTALL_PATH/bin/dummy"
|
||||
|
2
test/fixtures/dummy_plugin/bin/list-all
vendored
2
test/fixtures/dummy_plugin/bin/list-all
vendored
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
versions_list=(1.0 1.1 2.0)
|
||||
echo ${versions_list[@]}
|
||||
echo "${versions_list[@]}"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo $(cat $1 | tr -d "dummy-")
|
||||
# shellcheck disable=SC2020
|
||||
< "$1" tr -d "dummy-"
|
||||
|
@ -1,13 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck source=lib/utils.sh
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/utils.sh
|
||||
|
||||
setup_asdf_dir() {
|
||||
BASE_DIR=$(mktemp -dt asdf.XXXX)
|
||||
HOME=$BASE_DIR/home
|
||||
ASDF_DIR=$HOME/.asdf
|
||||
mkdir -p $ASDF_DIR/plugins
|
||||
mkdir -p $ASDF_DIR/installs
|
||||
mkdir -p $ASDF_DIR/shims
|
||||
mkdir -p $ASDF_DIR/tmp
|
||||
mkdir -p "$ASDF_DIR/plugins"
|
||||
mkdir -p "$ASDF_DIR/installs"
|
||||
mkdir -p "$ASDF_DIR/shims"
|
||||
mkdir -p "$ASDF_DIR/tmp"
|
||||
PATH=$ASDF_DIR/shims:$PATH
|
||||
}
|
||||
|
||||
@ -31,11 +34,11 @@ install_dummy_version() {
|
||||
}
|
||||
|
||||
clean_asdf_dir() {
|
||||
rm -rf $BASE_DIR
|
||||
rm -rf "$BASE_DIR"
|
||||
unset ASDF_DIR
|
||||
}
|
||||
|
||||
setup_repo() {
|
||||
cp -r $BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo $ASDF_DIR/repository
|
||||
cp -r "$BATS_TEST_DIRNAME"/fixtures/dummy_plugins_repo "$ASDF_DIR"/repository
|
||||
touch "$(asdf_dir)/tmp/repo-updated"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user