mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge latest master
This commit is contained in:
commit
18ed5c106a
8
.travis.yml
Normal file
8
.travis.yml
Normal file
@ -0,0 +1,8 @@
|
||||
language: c
|
||||
script: bats test
|
||||
before_script:
|
||||
- git clone https://github.com/sstephenson/bats.git /tmp/bats
|
||||
- export PATH=/tmp/bats/bin:$PATH
|
||||
os:
|
||||
- linux
|
||||
- osx
|
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Akash Manohar J
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
64
README.md
64
README.md
@ -1,14 +1,14 @@
|
||||
# asdf
|
||||
### _extendable version manager_
|
||||
|
||||
Supported languages include Ruby, Node.js, Elixir and more. Supporting a new language is as simple as [this plugin API](https://github.com/HashNuke/asdf/blob/master/docs/creating-plugins.md).
|
||||
Supported languages include Ruby, Node.js, Elixir and more. Supporting a new language is as simple as [this plugin API](https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md).
|
||||
|
||||
## SETUP
|
||||
|
||||
Copy-paste the following into command line:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/HashNuke/asdf.git ~/.asdf
|
||||
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
|
||||
|
||||
```
|
||||
|
||||
@ -16,16 +16,25 @@ Depending on your OS, run the following
|
||||
```bash
|
||||
# For Ubuntu or other linux distros
|
||||
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
|
||||
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
|
||||
|
||||
# OR for Max OSX
|
||||
echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
|
||||
echo '. $HOME/.asdf/completions/asdf.bash' >> ~/.bash_profile
|
||||
```
|
||||
|
||||
If you use zsh or any other shell, replace `.bashrc` with the config file for the respective shell.
|
||||
|
||||
For fish, you can use the following:
|
||||
|
||||
```
|
||||
echo 'source ~/.asdf/asdf.fish' >> ~/.config/fish/config.fish
|
||||
mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.config/fish/completions
|
||||
```
|
||||
|
||||
> For most plugins, it is good if you have installed the following packages OR their equivalent on you OS
|
||||
|
||||
> * **OS X**: Install these via homebrew `automake autoconf openssl libyaml readline ncurses libxslt libtool unixodbc`
|
||||
> * **OS X**: Install these via homebrew `automake autoconf openssl libyaml readline libxslt libtool unixodbc`
|
||||
> * **Ubuntu**: `automake autoconf libreadline-dev libncurses-dev libssl-dev libyaml-dev libxslt-dev libffi-dev libtool unixodbc-dev`
|
||||
|
||||
**That's all ~! You are ready to use asdf**
|
||||
@ -37,22 +46,27 @@ If you use zsh or any other shell, replace `.bashrc` with the config file for th
|
||||
|
||||
### Manage plugins
|
||||
|
||||
Plugins are how asdf understands how to handle different packages. Below is a list of plugins for languages. There is a [super-simple API](https://github.com/HashNuke/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
|
||||
Plugins are how asdf understands how to handle different packages. Below is a list of plugins for languages. There is a [super-simple API](https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
|
||||
|
||||
| Language | Repository |
|
||||
|----------|-------------|
|
||||
| Elixir | [HashNuke/asdf-elixir](https://github.com/HashNuke/asdf-elixir)
|
||||
| Erlang | [HashNuke/asdf-erlang](https://github.com/HashNuke/asdf-erlang)
|
||||
| Lua | [Stratus3D/asdf-lua](https://github.com/Stratus3D/asdf-lua)
|
||||
| Node.js | [HashNuke/asdf-nodejs](https://github.com/HashNuke/asdf-nodejs)
|
||||
| Ruby | [HashNuke/asdf-ruby](https://github.com/HashNuke/asdf-ruby)
|
||||
| Language | Repository |
|
||||
|-----------|-------------|
|
||||
| Elixir | [asdf-vm/asdf-elixir](https://github.com/asdf-vm/asdf-elixir)
|
||||
| Erlang | [asdf-vm/asdf-erlang](https://github.com/asdf-vm/asdf-erlang)
|
||||
| Go | [kennyp/asdf-golang](https://github.com/kennyp/asdf-golang)
|
||||
| Lua | [Stratus3D/asdf-lua](https://github.com/Stratus3D/asdf-lua)
|
||||
| OpenResty | [smashedtoatoms/asdf-openresty](https://github.com/smashedtoatoms/asdf-openresty)
|
||||
| Node.js | [asdf-vm/asdf-nodejs](https://github.com/asdf-vm/asdf-nodejs)
|
||||
| Postgres | [smashedtoatoms/asdf-postgres](https://github.com/smashedtoatoms/asdf-postgres)
|
||||
| Redis | [smashedtoatoms/asdf-redis](https://github.com/smashedtoatoms/asdf-redis)
|
||||
| Riak | [smashedtoatoms/asdf-riak](https://github.com/smashedtoatoms/asdf-riak)
|
||||
| Ruby | [asdf-vm/asdf-ruby](https://github.com/asdf-vm/asdf-ruby)
|
||||
|
||||
|
||||
##### Add a plugin
|
||||
|
||||
```bash
|
||||
asdf plugin-add <name> <git-url>
|
||||
# asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
|
||||
# asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
|
||||
```
|
||||
|
||||
##### List installed plugins
|
||||
@ -113,6 +127,26 @@ asdf list-all <name>
|
||||
# asdf list-all erlang
|
||||
```
|
||||
|
||||
#### View current version
|
||||
|
||||
```bash
|
||||
asdf local [name]
|
||||
asdf global [name]
|
||||
# asdf local
|
||||
# asdf global
|
||||
# asdf local elixir
|
||||
# asdf global elixir
|
||||
```
|
||||
|
||||
#### Set current version
|
||||
|
||||
```bash
|
||||
asdf global <name> <version>
|
||||
asdf local <name> <version>
|
||||
asdf global elixir 1.2.4
|
||||
```
|
||||
|
||||
|
||||
## The `.tool-versions` file
|
||||
|
||||
Add a `.tool-versions` file to your project dir and versions of those tools will be used.
|
||||
@ -133,12 +167,14 @@ The versions can be in the following format:
|
||||
|
||||
To install all the tools defined in a `.tool-versions` file run the `asdf install` command with no other arguments in the directory containing the `.tool-versions` file.
|
||||
|
||||
You can view/modify the file by hand or use `asdf local` and `asdf global` to manage it.
|
||||
|
||||
## Credits
|
||||
|
||||
Me ([@HashNuke](http://github.com/HashNuke)), High-fever, cold, cough.
|
||||
|
||||
Copyright 2014 to the end of time
|
||||
Copyright 2014 to the end of time ([MIT License](https://github.com/asdf-vm/asdf/blob/master/LICENSE))
|
||||
|
||||
-------
|
||||
|
||||
Read the [ballad](https://github.com/HashNuke/asdf/blob/master/ballad-of-asdf.md).
|
||||
Read the [ballad](https://github.com/asdf-vm/asdf/blob/master/ballad-of-asdf.md).
|
||||
|
8
asdf.fish
Normal file
8
asdf.fish
Normal file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env fish
|
||||
|
||||
set -l asdf_dir (dirname (status -f))
|
||||
|
||||
# we get an ugly warning when setting the path if shims does not exist
|
||||
mkdir -p $asdf_dir/shims
|
||||
|
||||
set -xg PATH $asdf_dir/bin $asdf_dir/shims $PATH
|
6
asdf.sh
6
asdf.sh
@ -8,3 +8,9 @@ fi
|
||||
|
||||
asdf_dir=$(cd $(dirname $current_script_path); echo $(pwd))
|
||||
export PATH="${asdf_dir}/bin:${asdf_dir}/shims:$PATH"
|
||||
|
||||
if [ -n "$ZSH_VERSION" ]; then
|
||||
fpath=(${asdf_dir}/completions $fpath)
|
||||
autoload -U compinit
|
||||
compinit
|
||||
fi
|
||||
|
7
bin/asdf
7
bin/asdf
@ -7,6 +7,7 @@ source $(dirname $(dirname $0))/lib/commands/install.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/uninstall.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/which.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/where.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
|
||||
@ -40,6 +41,12 @@ case $1 in
|
||||
"where")
|
||||
where_command $callback_args;;
|
||||
|
||||
"local")
|
||||
local_command $callback_args;;
|
||||
|
||||
"global")
|
||||
global_command $callback_args;;
|
||||
|
||||
"list")
|
||||
list_command $callback_args;;
|
||||
|
||||
|
3
completions/_asdf
Normal file
3
completions/_asdf
Normal file
@ -0,0 +1,3 @@
|
||||
#compdef asdf
|
||||
|
||||
_arguments "1: :(plugin-add plugin-list plugin-remove plugin-update install uninstall which where list list-all reshim)"
|
43
completions/asdf.bash
Normal file
43
completions/asdf.bash
Normal file
@ -0,0 +1,43 @@
|
||||
#!/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' ' ')
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
case "$cmd" in
|
||||
plugin-update)
|
||||
COMPREPLY=($(compgen -W "$plugins --all" -- $cur))
|
||||
;;
|
||||
plugin-remove|which|list|list-all)
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
;;
|
||||
install)
|
||||
if [[ "$plugins" == *"$prev"* ]] ; then
|
||||
local versions=$(asdf list-all $prev)
|
||||
COMPREPLY=($(compgen -W "$versions" -- $cur))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
fi
|
||||
;;
|
||||
uninstall|where|reshim)
|
||||
if [[ "$plugins" == *"$prev"* ]] ; then
|
||||
local versions=$(asdf list $prev)
|
||||
COMPREPLY=($(compgen -W "$versions" -- $cur))
|
||||
else
|
||||
COMPREPLY=($(compgen -W "$plugins" -- $cur))
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall which where list list-all reshim'
|
||||
COMPREPLY=($(compgen -W "$cmds" -- $cur))
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -F _asdf asdf
|
93
completions/asdf.fish
Normal file
93
completions/asdf.fish
Normal file
@ -0,0 +1,93 @@
|
||||
function __fish_asdf_needs_command
|
||||
set -l cmd (commandline -opc)
|
||||
if test (count $cmd) -eq 1
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_asdf_using_command -a current_command
|
||||
set -l cmd (commandline -opc)
|
||||
if test (count $cmd) -gt 1
|
||||
if test $current_command = $cmd[2]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_asdf_arg_number -a number
|
||||
set -l cmd (commandline -opc)
|
||||
test (count $cmd) -eq $number
|
||||
end
|
||||
|
||||
function __fish_asdf_arg_at -a number
|
||||
set -l cmd (commandline -opc)
|
||||
echo $cmd[$number]
|
||||
end
|
||||
|
||||
set -l official_plugins ruby erlang nodejs elixir
|
||||
|
||||
|
||||
# plugin-add completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-add -d "Add git repo as plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 2' -a (echo $official_plugins)
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 3' -a '(echo https://github.com/asdf-vm/asdf-(__fish_asdf_arg_at 3).git)'
|
||||
|
||||
# plugin-list completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list -d "List installed plugins"
|
||||
|
||||
# plugin-remove completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-remove -d "Remove plugin and package versions"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-remove; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)' -A
|
||||
|
||||
# plugin-update completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-update -d "Update plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)' -A
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a --all -A
|
||||
|
||||
# install completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a install -d "Install a specific version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 3' -a '(asdf list-all (__fish_asdf_arg_at 3))'
|
||||
|
||||
# uninstall completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a specific version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
|
||||
|
||||
# which completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a which -d "Display version set or being used for package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command which; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
|
||||
# where completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
|
||||
|
||||
# list completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a list -d "List installed versions of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command list; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
|
||||
# list-all completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a list-all -d "List all versions of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command list-all; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
|
||||
# reshim completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a reshim -d "Recreate shims for version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
|
||||
|
||||
# local completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
|
||||
|
||||
# global completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
|
||||
|
||||
# misc
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -l "version" -d "Displays asdf version"
|
2
defaults
Normal file
2
defaults
Normal file
@ -0,0 +1,2 @@
|
||||
# enables the use of .ruby-version like files used by other version managers
|
||||
legacy_version_file = no
|
4
help.txt
4
help.txt
@ -13,6 +13,10 @@ MANAGE PACKAGES
|
||||
asdf uninstall <name> <version> Remove a specific version of a package
|
||||
asdf which <name> Display version set or being used for package
|
||||
asdf where <name> <version> Display install path for an installed version
|
||||
asdf local [name] Display a package local version
|
||||
asdf local <name> <version> Set the package local version
|
||||
asdf global [name] Display a package global version
|
||||
asdf global <name> <version> Set the package global version
|
||||
asdf list <name> List installed versions of a package
|
||||
asdf list-all <name> List all versions of a package
|
||||
|
||||
|
@ -14,19 +14,14 @@ install_local_tool_versions() {
|
||||
if [ -f $(pwd)/.tool-versions ]; then
|
||||
local asdf_versions_path=$(pwd)/.tool-versions
|
||||
|
||||
local read_done=false
|
||||
until $read_done; do
|
||||
read tool_line || read_done=true
|
||||
|
||||
if $read_done ; then
|
||||
break;
|
||||
fi
|
||||
|
||||
while read tool_line; do
|
||||
IFS=' ' read -a tool_info <<< $tool_line
|
||||
local t_name=$(echo "${tool_info[0]}" | xargs)
|
||||
local t_version=$(echo "${tool_info[1]}" | xargs)
|
||||
local tool_name=$(echo "${tool_info[0]}" | xargs)
|
||||
local tool_version=$(echo "${tool_info[1]}" | xargs)
|
||||
|
||||
install_command $t_name $t_version
|
||||
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
|
||||
install_tool_version $tool_name $tool_version
|
||||
fi
|
||||
done < $asdf_versions_path
|
||||
else
|
||||
echo "Either specify a tool & version in the command"
|
||||
|
60
lib/commands/version_commands.sh
Normal file
60
lib/commands/version_commands.sh
Normal file
@ -0,0 +1,60 @@
|
||||
version_command() {
|
||||
local cmd=$1
|
||||
|
||||
if [ $# -gt 3 ]; then
|
||||
echo usage: $cmd [PLUGIN] [VERSION]
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local file
|
||||
if [ $cmd = "global" ]; then
|
||||
file=$HOME/.tool-versions
|
||||
else
|
||||
file=$(get_asdf_versions_file_path)
|
||||
if [ -z "$file" ]; then
|
||||
file=.tool-versions
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $# -ne 3 -a ! -f $file ]; then
|
||||
echo $file does not exist
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
cat $file
|
||||
exit 0
|
||||
fi
|
||||
|
||||
local plugin=$2
|
||||
check_if_plugin_exists $(get_plugin_path $plugin)
|
||||
|
||||
if [ $# -eq 2 ]; then
|
||||
result=$(get_tool_version_from_file $file $plugin)
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
exit 0
|
||||
else
|
||||
echo "version not set for $plugin"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
local version=$3
|
||||
|
||||
check_if_version_exists $plugin $version
|
||||
|
||||
if [ -f $file ] && grep $plugin $file > /dev/null; then
|
||||
sed -i -e "s/$plugin .*/$plugin $version/" $file
|
||||
else
|
||||
echo "$plugin $version" >> $file
|
||||
fi
|
||||
}
|
||||
|
||||
local_command() {
|
||||
version_command "local" $@
|
||||
}
|
||||
|
||||
global_command() {
|
||||
version_command "global" $@
|
||||
}
|
42
lib/utils.sh
42
lib/utils.sh
@ -36,6 +36,16 @@ check_if_plugin_exists() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_if_version_exists() {
|
||||
local plugin=$1
|
||||
local version=$2
|
||||
local version_dir=$(asdf_dir)/installs/$plugin/$version
|
||||
if [ ! -d $version_dir ]; then
|
||||
display_error "version $version is not installed for $plugin"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_version_part() {
|
||||
IFS='@' read -a version_info <<< "$1"
|
||||
@ -62,7 +72,7 @@ get_asdf_versions_file_path() {
|
||||
asdf_tool_versions_path="$search_path/.tool-versions"
|
||||
break
|
||||
fi
|
||||
search_path=$(dirname $search_path)
|
||||
search_path=$(dirname "$search_path")
|
||||
done
|
||||
|
||||
echo $asdf_tool_versions_path
|
||||
@ -129,6 +139,7 @@ get_tool_version_from_file() {
|
||||
echo $matching_tool_version
|
||||
}
|
||||
|
||||
|
||||
get_tool_version_from_legacy_file() {
|
||||
local plugin_name=$1
|
||||
local directory=$2
|
||||
@ -144,3 +155,32 @@ get_tool_version_from_legacy_file() {
|
||||
# Should return the version/tag/commit/branch/path
|
||||
echo $legacy_tool_version
|
||||
}
|
||||
|
||||
|
||||
get_asdf_config_value_from_file() {
|
||||
local config_path=$1
|
||||
local key=$2
|
||||
|
||||
if [ ! -f $config_path ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local result=$(grep -E "^\s*$key\s*=" $config_path | awk -F '=' '{ gsub(/ /, "", $2); print $2 }')
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
fi
|
||||
}
|
||||
|
||||
get_asdf_config_value() {
|
||||
local key=$1
|
||||
local config_path=${AZDF_CONFIG_FILE:-"$HOME/.asdfrc"}
|
||||
local default_config_path=${AZDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}
|
||||
|
||||
local result=$(get_asdf_config_value_from_file $config_path $key)
|
||||
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
else
|
||||
get_asdf_config_value_from_file $default_config_path $key
|
||||
fi
|
||||
}
|
||||
|
39
test/get_asdf_config_value.bats
Normal file
39
test/get_asdf_config_value.bats
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/utils.sh
|
||||
|
||||
setup() {
|
||||
AZDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc
|
||||
cat > $AZDF_CONFIG_FILE <<-EOM
|
||||
key1 = value1
|
||||
legacy_version_file = yes
|
||||
EOM
|
||||
|
||||
AZDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults
|
||||
cat > $AZDF_CONFIG_DEFAULT_FILE <<-EOM
|
||||
# i have a comment, it's ok
|
||||
key2 = value2
|
||||
legacy_version_file = no
|
||||
EOM
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm $AZDF_CONFIG_FILE
|
||||
rm $AZDF_CONFIG_DEFAULT_FILE
|
||||
unset AZDF_CONFIG_DEFAULT_FILE
|
||||
unset AZDF_CONFIG_FILE
|
||||
}
|
||||
|
||||
@test "get_config returns default when config file does not exist" {
|
||||
result=$(AZDF_CONFIG_FILE="/some/fake/path" get_asdf_config_value "legacy_version_file")
|
||||
[ "$result" = "no" ]
|
||||
}
|
||||
|
||||
@test "get_config returns default value when the key does not exist" {
|
||||
[ $(get_asdf_config_value "key2") = "value2" ]
|
||||
}
|
||||
|
||||
@test "get_config returns config file value when key exists" {
|
||||
[ $(get_asdf_config_value "key1") = "value1" ]
|
||||
[ $(get_asdf_config_value "legacy_version_file") = "yes" ]
|
||||
}
|
33
test/utils.bats
Normal file
33
test/utils.bats
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/utils.sh
|
||||
|
||||
setup() {
|
||||
ASDF_DIR=$(mktemp -dt asdf.XXXX)
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf $ASDF_DIR
|
||||
unset ASDF_DIR
|
||||
}
|
||||
|
||||
@test "check_if_version_exists should exit with 1 if plugin does not exist" {
|
||||
mkdir -p $ASDF_DIR/installs
|
||||
run check_if_version_exists "foo" "1.0.0"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "version 1.0.0 is not installed for foo" ]
|
||||
}
|
||||
|
||||
@test "check_if_version_exists should exit with 1 if version does not exist" {
|
||||
mkdir -p $ASDF_DIR/installs/foo
|
||||
run check_if_version_exists "foo" "1.0.0"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "version 1.0.0 is not installed for foo" ]
|
||||
}
|
||||
|
||||
@test "check_if_version_exists should be noop if version exists" {
|
||||
mkdir -p $ASDF_DIR/installs/foo/1.0.0
|
||||
run check_if_version_exists "foo" "1.0.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
83
test/version_commands.bats
Normal file
83
test/version_commands.bats
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/utils.sh
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/version_commands.sh
|
||||
|
||||
setup() {
|
||||
BASE_DIR=$(mktemp -dt asdf.XXXX)
|
||||
HOME=$BASE_DIR/home
|
||||
ASDF_DIR=$HOME/.asdf
|
||||
OTHER_DIR=$BASE_DIR/other
|
||||
mkdir -p $ASDF_DIR/plugins/foo $ASDF_DIR/plugins/bar $ASDF_DIR/installs/foo/1.0.0 $ASDF_DIR/installs/foo/1.1.0 $ASDF_DIR/installs/foo/1.2.0 $ASDF_DIR/installs/bar/1.0.0 $OTHER_DIR
|
||||
|
||||
cd $OTHER_DIR
|
||||
echo 'foo 1.0.0' >> $HOME/.tool-versions
|
||||
echo 'foo 1.1.0' >> .tool-versions
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf $BASE_DIR
|
||||
}
|
||||
|
||||
|
||||
@test "local should emit an error when run in lookup mode and file does not exist" {
|
||||
rm .tool-versions
|
||||
run local_command
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = ".tool-versions does not exist" ]
|
||||
}
|
||||
|
||||
@test "global should emit an error when run in lookup mode and file does not exist" {
|
||||
rm $HOME/.tool-versions
|
||||
run global_command "foo"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "$HOME/.tool-versions does not exist" ]
|
||||
}
|
||||
|
||||
@test "local should emit an error when plugin does not exist" {
|
||||
run local_command "inexistent" "1.0.0"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "No such plugin" ]
|
||||
}
|
||||
|
||||
@test "local should emit an error when plugin version does not exist" {
|
||||
run local_command "foo" "0.0.1"
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "version 0.0.1 is not installed for foo" ]
|
||||
}
|
||||
|
||||
@test "local should return and set the local version" {
|
||||
|
||||
run local_command
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "foo 1.1.0" ]
|
||||
|
||||
run local_command foo "1.2.0"
|
||||
|
||||
run local_command foo
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.2.0" ]
|
||||
|
||||
run local_command bar
|
||||
[ "$status" -eq 1 ]
|
||||
|
||||
run local_command bar 1.0.0
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run local_command bar
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.0.0" ]
|
||||
}
|
||||
|
||||
@test "global should return and set the global version" {
|
||||
run global_command
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "foo 1.0.0" ]
|
||||
|
||||
run global_command foo 1.2.0
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run global_command foo
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "1.2.0" ]
|
||||
}
|
Loading…
Reference in New Issue
Block a user