Merge branch 'master' into which_command

This commit is contained in:
Fernando 2017-05-15 15:40:42 -03:00 committed by GitHub
commit 1e9166e9bc
17 changed files with 301 additions and 91 deletions

View File

@ -1,13 +1,21 @@
#Changelog
# Changelog
##0.2.1-dev
## 0.3.1-dev
## 0.3.0
Features
* Add `update` command to make it easier to update asdf to the latest release (#172, #180)
* Add support for `system` version to allow passthrough to system installed tools (#55, #182)
Fixed Bugs
* Set `GREP_OPTIONS` and `GREP_COLORS` variables in util.sh so grep is always invoked with the correct settings (#170)
* Export `ASDF_DIR` variable so the Zsh plugin can locate asdf if it's in a custom location (#156)
* Don't add execute permission to files in a plugin's bin directory when adding the plugin (#124, #138, #154)
##0.2.1
## 0.2.1
Features
@ -19,7 +27,7 @@ Fixed Bugs
* Remove shims when uninstalling a version or removing a plugin (#122, #123, #125, #128, #131)
* Add a helpful error message to the install command (#135)
##0.2.0
## 0.2.0
Features
@ -32,6 +40,6 @@ Fixed Bugs
* Fix bug that caused the `local` command to crash when the directory contains whitespace (#90)
* Misc typo corrections (#93, #99)
##0.1.0
## 0.1.0
* First tagged release

View File

@ -8,7 +8,7 @@ Supported languages include Ruby, Node.js, Elixir and more. Supporting a new lan
Copy-paste the following into command line:
```bash
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.2.1
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.3.0
```
Depending on your OS, run the following
@ -49,7 +49,7 @@ mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.con
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 | CI Status
|-----------|-------------|----------
|-----------|-------------|----------
| Clojure | [vic/asdf-clojure](https://github.com/vic/asdf-clojure) | [![Build Status](https://travis-ci.org/vic/asdf-clojure.svg?branch=master)](https://travis-ci.org/vic/asdf-clojure)
| Crystal | [marciogm/asdf-crystal](https://github.com/marciogm/asdf-crystal) | [![Build Status](https://travis-ci.org/marciogm/asdf-crystal.svg?branch=master)](https://travis-ci.org/marciogm/asdf-crystal)
| D (DMD) | [sylph01/asdf-dmd](https://github.com/sylph01/asdf-dmd) | [![Build Status](https://travis-ci.org/sylph01/asdf-dmd.svg?branch=master)](https://travis-ci.org/sylph01/asdf-dmd)
@ -193,6 +193,7 @@ The versions can be in the following format:
* `0.12.3` - an actual version. Plugins that support downloading binaries, will download binaries.
* `ref:v1.0.2-a` or `ref:39cb398vb39` - tag/commit/branch to download from github and compile
* `path:/src/elixir` - a path to custom compiled version of a tool to use. For use by language developers and such.
* `system` - this keyword causes asdf to passthrough to the version of the tool on the system that is not managed by asdf.
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.
@ -212,14 +213,14 @@ legacy_version_file = yes
## Credits
Me ([@HashNuke](http://github.com/HashNuke)), High-fever, cold, cough.
Me ([@HashNuke](https://github.com/HashNuke)), High-fever, cold, cough.
Copyright 2014 to the end of time ([MIT License](https://github.com/asdf-vm/asdf/blob/master/LICENSE))
### Maintainers
- [@HashNuke](http://github.com/HashNuke)
- [@tuvistavie](http://github.com/tuvistavie)
- [@HashNuke](https://github.com/HashNuke)
- [@tuvistavie](https://github.com/tuvistavie)
- [@Stratus3D](https://github.com/Stratus3D)
- [@vic](https://github.com/vic)

View File

@ -1,30 +1,30 @@
# Ballad of asdf
> Once upon a time there was a programming language
There were many versions of it
So people wrote a version manager for it
To switch between versions for projects
Different, old, new.
> Once upon a time there was a programming language
There were many versions of it
So people wrote a version manager for it
To switch between versions for projects
Different, old, new.
> Then there came more programming languages
So there came more version managers
And many commands for them
> Then there came more programming languages
So there came more version managers
And many commands for them
> I installed a lot of them
I learnt a lot of commands
I learnt a lot of commands
> Then I said, just one more version manager
Which I will write instead
> Then I said, just one more version manager
Which I will write instead
> So, there came another version manager
**asdf version manager** - <https://github.com/HashNuke/asdf>
> So, there came another version manager
**asdf version manager** - <https://github.com/HashNuke/asdf>
> A version manager so extendable
for which anyone can create a plugin
To support their favourite language
No more installing more version managers
> A version manager so extendable
for which anyone can create a plugin
To support their favourite language
No more installing more version managers
Or learning more commands
---
*This was the mail I wrote to a few friends to tell them about the project. Thanks to [@roshanvid](http://twitter.com/roshanvid) for suggesting that this go into the readme*
*This was the mail I wrote to a few friends to tell them about the project. Thanks to [@roshanvid](https://twitter.com/roshanvid) for suggesting that this go into the readme*

View File

@ -3,6 +3,7 @@
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
@ -31,6 +32,9 @@ case $1 in
"help")
help_command $callback_args;;
"update")
update_command $callback_args;;
"install")
install_command $callback_args;;

View File

@ -18,33 +18,16 @@ fi
IFS=' ' read -a versions <<< "$full_version"
for version in "${versions[@]}"; do
IFS=':' read -a version_info <<< "$version"
install_path=$(find_install_path $plugin_name $version)
if [ "${version_info[0]}" = "ref" ]; then
install_type="${version_info[0]}"
version="${version_info[1]}"
install_path=$(get_install_path $plugin_name $install_type $version)
elif [ "${version_info[0]}" = "path" ]; then
# This is for people who have the local source already compiled
# Like those who work on the language, etc
# We'll allow specifying path:/foo/bar/project in .tool-versions
# And then use the binaries there
install_type="path"
version="path"
install_path="${version_info[1]}"
else
install_type="version"
version="${version_info[0]}"
install_path=$(get_install_path $plugin_name $install_type $version)
fi
if [ ! -d $install_path ]; then
if [ $version != "system" ] && [ ! -d "$install_path" ]; then
echo "$plugin_name $version not installed"
exit 1
fi
if [ -f ${install_path}/${executable_path} ]; then
full_executable_path=$(get_executable_path $plugin_name $version $executable_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
@ -56,10 +39,9 @@ for version in "${versions[@]}"; do
unset ASDF_INSTALL_TYPE
unset ASDF_INSTALL_VERSION
unset ASDF_INSTALL_PATH
exec ${install_path}/${executable_path} "${@:3}"
else
exec ${install_path}/${executable_path} "${@:3}"
fi
exec $full_executable_path "${@:3}"
fi
done

View File

@ -23,7 +23,7 @@ _asdf () {
COMPREPLY=($(compgen -W "$plugins" -- $cur))
fi
;;
uninstall|where|reshim)
uninstall|where|reshim|local|global)
if [[ "$plugins" == *"$prev"* ]] ; then
local versions=$(asdf list $prev)
COMPREPLY=($(compgen -W "$versions" -- $cur))
@ -32,7 +32,7 @@ _asdf () {
fi
;;
*)
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall current where which list list-all reshim'
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))
;;
esac

View File

@ -81,12 +81,12 @@ complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_nu
# 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 test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3))'
complete -f -c asdf -n '__fish_asdf_using_command local; and test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3)) system'
# 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 test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3))'
complete -f -c asdf -n '__fish_asdf_using_command global; and test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3)) system'
# misc
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"

View File

@ -17,7 +17,7 @@ All scripts except `bin/list-all` will have access to the following env vars to
#### bin/list-all
Must print a string with a space-seperated list of versions. Example output would be the following:
Must print a string with a space-separated list of versions. Example output would be the following:
```
1.0.1 1.0.2 1.3.0 1.4
@ -36,7 +36,7 @@ This script should install the version, in the path mentioned in `ASDF_INSTALL_P
#### bin/list-bin-paths
List executables for the specified version of the tool. Must print a string with a space-seperated list of dir paths that contain executables. The paths must be relative to the install path passed. Example output would be:
List executables for the specified version of the tool. Must print a string with a space-separated list of dir paths that contain executables. The paths must be relative to the install path passed. Example output would be:
```
bin tools veggies
@ -56,7 +56,7 @@ Uninstalls a specific version of a tool.
#### bin/list-legacy-filenames
Register additional setter files for this plugin. Must print a string with a space-seperated list of filenames.
Register additional setter files for this plugin. Must print a string with a space-separated list of filenames.
```
.ruby-version .rvmrc

View File

@ -22,6 +22,8 @@ MANAGE PACKAGES
UTILS
asdf reshim <name> <version> Recreate shims for version of a package
asdf update Update asdf to the latest stable release
asdf update --head Update asdf to the latest on the master branch
"Late but latest"

View File

@ -70,5 +70,15 @@ plugin_test_command() {
fi
done
# Assert that a license file exists in the plugin repo and is not empty
license_file="$ASDF_DIR/plugins/$plugin_name/LICENSE"
if [ -f "$license_file" ]; then
if [ ! -s "$license_file" ]; then
fail_test "LICENSE file in the plugin repository must not be empty"
fi
else
fail_test "LICENSE file must be present in the plugin repository"
fi
rm -rf $ASDF_DIR
}

View File

@ -97,17 +97,17 @@ generate_shims_for_version() {
local install_path=$(get_install_path $plugin_name $install_type $version)
if [ -f ${plugin_path}/bin/list-bin-paths ]; then
local space_seperated_list_of_bin_paths=$(
local space_separated_list_of_bin_paths=$(
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
bash ${plugin_path}/bin/list-bin-paths
)
else
local space_seperated_list_of_bin_paths="bin"
local space_separated_list_of_bin_paths="bin"
fi
IFS=' ' read -a all_bin_paths <<< "$space_seperated_list_of_bin_paths"
IFS=' ' read -a all_bin_paths <<< "$space_separated_list_of_bin_paths"
for bin_path in "${all_bin_paths[@]}"; do
for executable_file in $install_path/$bin_path/*; do

30
lib/commands/update.sh Normal file
View File

@ -0,0 +1,30 @@
update_command() {
local update_to_head=$1
(
cd $(asdf_dir)
if [ "$update_to_head" = "--head" ]; then
# Update to latest on the master branch
git checkout master
# Pull down the latest changes on master
git pull origin master
echo "Updated asdf to latest on the master branch"
else
# Update to latest release
git fetch --tags || exit 1
tag=$(git tag | sort_versions | sed '$!d') || exit 1
# Update
git checkout "$tag" || exit 1
echo "Updated asdf to release $tag"
fi
)
}
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

View File

@ -4,7 +4,11 @@ GREP_OPTIONS="--color=never"
GREP_COLORS=
asdf_version() {
echo "0.2.1"
# Move to the asdf repo, then report the current tag
(
cd $(asdf_dir)
git describe --tags
)
}
asdf_dir() {
@ -46,7 +50,7 @@ list_installed_versions() {
check_if_plugin_exists() {
# Check if we have a non-empty argument
if [ -z "${1+set}" ]; then
display_error "No such plugin"
display_error "No plugin given"
exit 1
fi
@ -57,17 +61,19 @@ check_if_plugin_exists() {
}
check_if_version_exists() {
local plugin=$1
local plugin_name=$1
local version=$2
local version_dir=$(asdf_dir)/installs/$plugin/$version
local version_dir=$(asdf_dir)/installs/$plugin_name/$version
# if version starts with path: use that directory
if [ "${version/path:}" != "$version" ]; then
version_dir=$(echo $version | cut -d: -f 2)
fi
if [ ! -d $version_dir ]; then
display_error "version $version is not installed for $plugin"
check_if_plugin_exists $plugin_name
if [ "$version" != "system" ] && [ ! -d $version_dir ]; then
display_error "version $version is not installed for $plugin_name"
exit 1
fi
}
@ -141,6 +147,54 @@ get_version_from_env () {
echo "$version"
}
find_install_path() {
local plugin_name=$1
local version=$2
IFS=':' read -a version_info <<< "$version"
if [ $version = "system" ]; then
echo ""
elif [ "${version_info[0]}" = "ref" ]; then
local install_type="${version_info[0]}"
local version="${version_info[1]}"
echo $(get_install_path $plugin_name $install_type $version)
elif [ "${version_info[0]}" = "path" ]; then
# This is for people who have the local source already compiled
# Like those who work on the language, etc
# We'll allow specifying path:/foo/bar/project in .tool-versions
# And then use the binaries there
local install_type="path"
local version="path"
echo "${version_info[1]}"
else
local install_type="version"
local version="${version_info[0]}"
echo $(get_install_path $plugin_name $install_type $version)
fi
}
get_executable_path() {
local plugin_name=$1
local version=$2
local executable_path=$3
check_if_version_exists $plugin_name $version
if [ $version = "system" ]; then
path=$(echo $PATH | sed -e "s|$ASDF_DIR/shims||g; s|::|:|g")
cmd=$(basename $executable_path)
cmd_path=$(PATH=$path which $cmd 2>&1)
if [ $? -ne 0 ]; then
return 1
fi
echo $cmd_path
else
local install_path=$(find_install_path $plugin_name $version)
echo ${install_path}/${executable_path}
fi
}
parse_asdf_version_file() {
local file_path=$1
local plugin_name=$2
@ -180,29 +234,29 @@ get_preset_version_for() {
}
get_asdf_config_value_from_file() {
local config_path=$1
local key=$2
local config_path=$1
local key=$2
if [ ! -f $config_path ]; then
return 0
fi
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
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 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)
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
if [ -n "$result" ]; then
echo $result
else
get_asdf_config_value_from_file $default_config_path $key
fi
}

View File

@ -25,7 +25,7 @@ teardown() {
@test "plugin_remove_command should exit with 1 when not passed any arguments" {
run plugin_remove_command
[ "$status" -eq 1 ]
[ "$output" = "No such plugin" ]
[ "$output" = "No plugin given" ]
}
@test "plugin_remove_command should exit with 1 when passed invalid plugin name" {
@ -69,4 +69,4 @@ teardown() {
# unrelated shim should exist
[ -f $ASDF_DIR/shims/gummy ]
}
}

View File

@ -6,6 +6,8 @@ setup_asdf_dir() {
ASDF_DIR=$HOME/.asdf
mkdir -p $ASDF_DIR/plugins
mkdir -p $ASDF_DIR/installs
mkdir -p $ASDF_DIR/shims
PATH=$ASDF_DIR/shims:$PATH
}
install_dummy_plugin() {

79
test/update_command.bats Normal file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/update.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/uninstall.sh
setup() {
setup_asdf_dir
install_dummy_plugin
# Copy over git repo so we have something to test with
cp -r .git $ASDF_DIR
(
cd $ASDF_DIR
git remote remove origin
git remote add origin https://github.com/asdf-vm/asdf.git
git checkout .
)
PROJECT_DIR=$HOME/project
mkdir $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
@test "update_command --head should checkout the master branch" {
run update_command --head
[ "$status" -eq 0 ]
cd $ASDF_DIR
# TODO: Figure out why this is failing
#[ $(git rev-parse --abbrev-ref HEAD) = "master" ]
}
@test "update_command should checkout the latest tag" {
run update_command
[ "$status" -eq 0 ]
cd $ASDF_DIR
local tag=$(git describe --tag)
echo $(git tag) | grep $tag
[ "$status" -eq 0 ]
}
@test "update_command should not remove plugin versions" {
run install_command dummy 1.1
[ "$status" -eq 0 ]
[ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ]
run update_command
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.1/version ]
run update_command --head
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.1/version ]
}
@test "update_command should not remove plugins" {
# dummy plugin is already installed
run update_command
[ "$status" -eq 0 ]
[ -d $ASDF_DIR/plugins/dummy ]
run update_command --head
[ "$status" -eq 0 ]
[ -d $ASDF_DIR/plugins/dummy ]
}
@test "update_command should not remove shims" {
run install_command dummy 1.1
[ -f $ASDF_DIR/shims/dummy ]
run update_command
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/shims/dummy ]
run update_command --head
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/shims/dummy ]
}

View File

@ -19,7 +19,7 @@ teardown() {
@test "check_if_version_exists should exit with 1 if plugin does not exist" {
run check_if_version_exists "inexistent" "1.0.0"
[ "$status" -eq 1 ]
[ "$output" = "version 1.0.0 is not installed for inexistent" ]
[ "$output" = "No such plugin" ]
}
@test "check_if_version_exists should exit with 1 if version does not exist" {
@ -34,10 +34,17 @@ teardown() {
[ "$output" = "" ]
}
@test "check_if_version_exists should be noop if version is system" {
mkdir -p $ASDF_DIR/plugins/foo
run check_if_version_exists "foo" "system"
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
@test "check_if_plugin_exists should exit with 1 when plugin is empty string" {
run check_if_plugin_exists
[ "$status" -eq 1 ]
[ "$output" = "No such plugin" ]
[ "$output" = "No plugin given" ]
}
@test "check_if_plugin_exists should be noop if plugin exists" {
@ -139,3 +146,34 @@ teardown() {
[ "$status" -eq 0 ]
[ "$output" = "path:/some/place with spaces" ]
}
@test "get_executable_path for system version should return system path" {
mkdir -p $ASDF_DIR/plugins/foo
run get_executable_path "foo" "system" "ls"
[ "$status" -eq 0 ]
[ "$output" = $(which ls) ]
}
@test "get_executable_path for system version should not use asdf shims" {
mkdir -p $ASDF_DIR/plugins/foo
touch $ASDF_DIR/shims/dummy_executable
chmod +x $ASDF_DIR/shims/dummy_executable
run which dummy_executable
[ "$status" -eq 0 ]
run get_executable_path "foo" "system" "dummy_executable"
[ "$status" -eq 1 ]
}
@test "get_executable_path for non system version should return relative path from plugin" {
mkdir -p $ASDF_DIR/plugins/foo
mkdir -p $ASDF_DIR/installs/foo/1.0.0/bin
executable_path=$ASDF_DIR/installs/foo/1.0.0/bin/dummy
touch $executable_path
chmod +x $executable_path
run get_executable_path "foo" "1.0.0" "bin/dummy"
[ "$status" -eq 0 ]
[ "$output" = "$executable_path" ]
}