Merge branch 'master' into add/keyring_support

This commit is contained in:
Trevor Brown 2017-08-11 15:36:23 -04:00 committed by GitHub
commit 2dfd123b27
27 changed files with 647 additions and 146 deletions

17
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,17 @@
### Steps to reproduce
Tell us what actions you performed before the issue occurred
### Expected behavior
Tell us what should have happened
### Actual behavior
Tell us what happened instead
### Environment
**OS**:
**asdf version**:

12
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,12 @@
# Summary
Provide a general description of the code changes in your pull request.
Fixes: List issue numbers here
## Other Information
If there is anything else that is relevant to your pull request include that
information here.
Thank you for contributing to asdf!

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
installs
plugins
shims
repository
.vagrant
keyrings

View File

@ -1,8 +1,27 @@
#Changelog
# Changelog
##0.2.1-dev
## 0.3.1-dev
##0.2.1
Features
* Add CONTRIBUTING guidelines and GitHub issue and pull request templates
Fixed Bugs
## 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
Features
@ -14,7 +33,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
@ -27,6 +46,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

39
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,39 @@
# How to Contribute to asdf
## Did you find a bug?
**Ensure the bug is actually an issue with asdf and not a plugin.** If the bug
only occurs when using one tool installed by asdf and not others it's likely an
issue with the asdf plugin. Find the plugin repository on
[asdf-vm/asdf-plugins](https://github.com/asdf-vm/asdf-plugins) and follow the
plugin creators instructions for reporting the bug.
**Ensure the bug was not already reported** by searching on GitHub under
[Issues](https://github.com/asdf-vm/asdf/issues).
If you are unable to find an open issue addressing the problem please [open
a new one](https://github.com/asdf-vm/asdf/issues/new). Please be as specific
as possible when reporting the issue. Include the observed behavior as well as
what you thought should have happened. Please also provide environmental
details like asdf version, shell, OS, etc...
## Did you write a patch that fixes a bug?
Open a new GitHub pull request with the patch. Refer to the [Development
section of the README](https://github.com/asdf-vm/asdf#development) for the
details on how to run the unit tests. Please make sure that unit tests pass on
Travis CI.
## Did you create a plugin for asdf?
Please read the [creating plugins](doc/creating-plugins.md) guide.
## Do you want to contribute the asdf documentation?
Documentation can always be improved! Right now there is just the
[README](README.md) and the [creating plugins](doc/creating-plugins.md) guide.
The [wiki](https://github.com/asdf-vm/asdf/wiki) exists but is in a state of
disrepair. If you see something that can be improved please submit a pull
request or edit the wiki.
Thanks for contributing!

View File

@ -1,15 +1,14 @@
# asdf [![Build Status](https://travis-ci.org/asdf-vm/asdf.svg?branch=master)](https://travis-ci.org/asdf-vm/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/asdf-vm/asdf/blob/master/docs/creating-plugins.md).
Supported languages include Ruby, Node.js, Elixir and [more](https://github.com/asdf-vm/asdf-plugins). 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/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
@ -34,7 +33,7 @@ mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.con
> For most plugins, it is good if you have installed the following packages OR their equivalent on your OS
> * **OS X**: Install these via homebrew `automake autoconf openssl libyaml readline libxslt libtool unixodbc`
> * **OS X**: Install these via homebrew `coreutils 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`
> * **Fedora**: `automake autoconf readline-devel ncurses-devel openssl-devel libyaml-devel libxslt-devel libffi-devel libtool unixODBC-devel`
@ -47,44 +46,24 @@ mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.con
### 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/asdf-vm/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
Plugins are how asdf understands how to handle different packages.
| 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)
| Elixir | [asdf-vm/asdf-elixir](https://github.com/asdf-vm/asdf-elixir) | [![Build Status](https://travis-ci.org/asdf-vm/asdf-elixir.svg?branch=master)](https://travis-ci.org/asdf-vm/asdf-elixir)
| Elm | [vic/asdf-elm](https://github.com/vic/asdf-elm) | [![Build Status](https://travis-ci.org/vic/asdf-elm.svg?branch=master)](https://travis-ci.org/vic/asdf-elm)
| Erlang | [asdf-vm/asdf-erlang](https://github.com/asdf-vm/asdf-erlang) | [![Build Status](https://travis-ci.org/asdf-vm/asdf-erlang.svg?branch=master)](https://travis-ci.org/asdf-vm/asdf-erlang)
| Go | [kennyp/asdf-golang](https://github.com/kennyp/asdf-golang) | [![Build Status](https://travis-ci.org/kennyp/asdf-golang.svg?branch=master)](https://travis-ci.org/kennyp/asdf-golang)
| Haskell | [vic/asdf-haskell](https://github.com/vic/asdf-haskell) | [![Build Status](https://travis-ci.org/vic/asdf-haskell.svg?branch=master)](https://travis-ci.org/vic/asdf-haskell)
| Idris | [vic/asdf-idris](https://github.com/vic/asdf-idris) | [![Build Status](https://travis-ci.org/vic/asdf-idris.svg?branch=master)](https://travis-ci.org/vic/asdf-idris)
| Julia | [rkyleg/asdf-julia](https://github.com/rkyleg/asdf-julia) | [![Build Status](https://travis-ci.org/rkyleg/asdf-julia.svg?branch=master)](https://travis-ci.org/rkyleg/asdf-julia)
| LFE | [vic/asdf-lfe](https://github.com/vic/asdf-lfe) | [![Build Status](https://travis-ci.org/vic/asdf-lfe.svg?branch=master)](https://travis-ci.org/vic/asdf-lfe)
| Link (system tools) | [vic/asdf-link](https://github.com/vic/asdf-link) | [![Build Status](https://travis-ci.org/vic/asdf-link.svg?branch=master)](https://travis-ci.org/vic/asdf-link)
| Lua | [Stratus3D/asdf-lua](https://github.com/Stratus3D/asdf-lua) | [![Build Status](https://travis-ci.org/Stratus3D/asdf-lua.svg?branch=master)](https://travis-ci.org/Stratus3D/asdf-lua)
| LuaJIT | [smashedtoatoms/asdf-luaJIT](https://github.com/smashedtoatoms/asdf-luaJIT) | [![Build Status](https://travis-ci.org/smashedtoatoms/asdf-luaJIT.svg?branch=master)](https://travis-ci.org/smashedtoatoms/asdf-luaJIT)
| MongoDB | [sylph01/asdf-mongodb](https://github.com/sylph01/asdf-mongodb) | [![Build Status](https://travis-ci.org/sylph01/asdf-mongodb.svg?branch=master)](https://travis-ci.org/sylph01/asdf-mongodb)
| Node.js | [asdf-vm/asdf-nodejs](https://github.com/asdf-vm/asdf-nodejs) | [![Build Status](https://travis-ci.org/asdf-vm/asdf-nodejs.svg?branch=master)](https://travis-ci.org/asdf-vm/asdf-nodejs)
| OpenResty | [smashedtoatoms/asdf-openresty](https://github.com/smashedtoatoms/asdf-openresty) | [![Build Status](https://travis-ci.org/smashedtoatoms/asdf-openresty.svg?branch=master)](https://travis-ci.org/smashedtoatoms/asdf-openresty)
| Packer | [gozer/asdf-packer](https://github.com/gozer/asdf-packer) | [![Build Status](https://travis-ci.org/gozer/asdf-packer.svg?branch=master)](https://travis-ci.org/gozer/asdf-packer)
| PHP | [odarriba/asdf-php](https://github.com/odarriba/asdf-php) | [![Build Status](https://travis-ci.org/odarriba/asdf-php.svg?branch=master)](https://travis-ci.org/odarriba/asdf-php)
| Postgres | [smashedtoatoms/asdf-postgres](https://github.com/smashedtoatoms/asdf-postgres) | [![Build Status](https://travis-ci.org/smashedtoatoms/asdf-postgres.svg?branch=master)](https://travis-ci.org/smashedtoatoms/asdf-postgres)
| Python | [tuvistavie/asdf-python](https://github.com/tuvistavie/asdf-python) | [![Build Status](https://travis-ci.org/tuvistavie/asdf-python.svg?branch=master)](https://travis-ci.org/tuvistavie/asdf-python)
| Redis | [smashedtoatoms/asdf-redis](https://github.com/smashedtoatoms/asdf-redis) | [![Build Status](https://travis-ci.org/smashedtoatoms/asdf-redis.svg?branch=master)](https://travis-ci.org/smashedtoatoms/asdf-redis)
| Riak | [smashedtoatoms/asdf-riak](https://github.com/smashedtoatoms/asdf-riak) | [![Build Status](https://travis-ci.org/smashedtoatoms/asdf-riak.svg?branch=master)](https://travis-ci.org/smashedtoatoms/asdf-riak)
| Ruby | [asdf-vm/asdf-ruby](https://github.com/asdf-vm/asdf-ruby) | [![Build Status](https://travis-ci.org/asdf-vm/asdf-ruby.svg?branch=master)](https://travis-ci.org/asdf-vm/asdf-ruby)
| Rust | [code-lever/asdf-rust](https://github.com/code-lever/asdf-rust) | [![Build Status](https://travis-ci.org/code-lever/asdf-rust.svg?branch=master)](https://travis-ci.org/code-lever/asdf-rust)
| SBT | [lerencao/asdf-sbt](https://github.com/lerencao/asdf-sbt) | [![Build Status](https://travis-ci.org/lerencao/asdf-sbt.svg?branch=master)](https://travis-ci.org/lerencao/asdf-sbt)
| Scala | [mtatheonly/asdf-scala](https://github.com/mtatheonly/asdf-scala)| [![Build Status](https://travis-ci.org/mtatheonly/asdf-scala.svg?branch=master)](https://travis-ci.org/mtatheonly/asdf-scala)
| Terraform | [neerfri/asdf-terraform](https://github.com/neerfri/asdf-terraform) | [![Build Status](https://travis-ci.org/neerfri/asdf-terraform.svg?branch=master)](https://travis-ci.org/neerfri/asdf-terraform)
You can find a list of all asdf plugins in the [plugins repository](https://github.com/asdf-vm/asdf-plugins).
There is a [super-simple API](https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
##### Add a plugin
```bash
asdf plugin-add <name>
# asdf plugin-add erlang
```
If the plugin you want to install is not part of the plugins repository, you can add it using its repository URL:
```bash
asdf plugin-add <name> <git-url>
# asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
# asdf plugin-add elm https://github.com/vic/asdf-elm
```
##### List installed plugins
@ -158,7 +137,7 @@ asdf current <name>
```bash
asdf global <name> <version>
asdf local <name> <version>
asdf global elixir 1.2.4
# asdf global elixir 1.2.4
```
`global` writes the version to `$HOME/.tool-versions`.
@ -193,6 +172,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.
@ -210,16 +190,34 @@ legacy_version_file = yes
* `legacy_version_file` - defaults to `no`. If set to yes it will cause plugins that support this feature to read the version files used by other version managers (e.g. `.ruby-version` in the case of Ruby's rbenv).
## Docker images
The [asdf-alpine](https://github.com/vic/asdf-alpine) and [asdf-ubuntu](https://github.com/vic/asdf-ubuntu) projects are an ongoing effort to provide Dockerized images of some asdf tools. You can use these docker images as base for your development servers, or for running your production apps.
## Development
To develop the project, you can simply `git clone` the master branch.
If you want to try out your changes without making change to your installed `asdf`,
you can set the `$ASDF_DIR` variable to the path where you cloned the repository,
and temporarily prepend the `bin` and `shims` directory of the directory to your path.
We use [bats](https://github.com/sstephenson/bats) for testing,
so make sure `bats test/` passes after you made your changes.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for the contribution guidelines.
## 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,13 +1,14 @@
#!/usr/bin/env bash
if [ "${BASH_SOURCE[0]}" != "" ]; then
current_script_path=${BASH_SOURCE[0]}
current_script_path="${BASH_SOURCE[0]}"
else
current_script_path=$0
current_script_path="$0"
fi
asdf_dir=$(cd $(dirname $current_script_path) &> /dev/null; echo $(pwd))
export PATH="${asdf_dir}/bin:${asdf_dir}/shims:$PATH"
export ASDF_DIR
ASDF_DIR="$(cd "$(dirname "$current_script_path")" &> /dev/null || exit 1; pwd)"
export PATH="${ASDF_DIR}/bin:${ASDF_DIR}/shims:$PATH"
if [ -n "$ZSH_VERSION" ]; then
autoload -U bashcompinit

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<br/>
> There were many versions of it<br/>
> So people wrote a version manager for it<br/>
> To switch between versions for projects<br/>
> 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<br/>
> So there came more version managers<br/>
> And many commands for them
> I installed a lot of them
I learnt a lot of commands
> I installed a lot of them<br/>
> 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<br/>
> 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<br/>
> **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
Or learning more commands
> A version manager so extendable<br/>
> for which anyone can create a plugin<br/>
> To support their favourite language<br/>
> No more installing more version managers<br/>
> 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,10 +3,12 @@
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
@ -30,6 +32,9 @@ case $1 in
"help")
help_command $callback_args;;
"update")
update_command $callback_args;;
"install")
install_command $callback_args;;
@ -42,6 +47,9 @@ case $1 in
"where")
where_command $callback_args;;
"which")
which_command $callback_args;;
"local")
local_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 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
@ -117,3 +117,11 @@ os:
- linux
- osx
```
## Submitting plugins to the official plugins repository
`asdf` can easily install plugins by specifying the plugin repository url, e.g. `plugin-add my-plugin https://github.com/user/asdf-my-plugin.git`.
To make it easier on your users, you can add your plugin to the official plugins repository to have your plugin listed and easily installable using a shorter command, e.g. `asdf plugin-add my-plugin`.
Follow the instruction at the plugins repository: [asdf-vm/asdf-plugins](https://github.com/asdf-vm/asdf-plugins).

View File

@ -1,5 +1,5 @@
MANAGE PLUGINS
asdf plugin-add <name> <git-url> Add git repo as plugin
asdf plugin-add <name> [<git-url>] Add a plugin
asdf plugin-list List installed plugins
asdf plugin-remove <name> Remove plugin and package versions
asdf plugin-update <name> Update plugin
@ -13,6 +13,7 @@ MANAGE PACKAGES
asdf uninstall <name> <version> Remove a specific version of a package
asdf current <name> Display current version set or being used for package
asdf where <name> <version> Display install path for an installed version
asdf which <name> Display install path for current version
asdf local <name> <version> Set the package local version
asdf global <name> <version> Set the package global version
asdf list <name> List installed versions of a package
@ -21,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

@ -1,3 +1,15 @@
handle_failure() {
local install_path="$1"
rm -rf "$install_path"
exit 1
}
handle_cancel() {
local install_path="$1"
echo -e "\nreceived sigint, cleaning up"
handle_failure "$install_path"
}
install_command() {
local plugin_name=$1
local full_version=$2
@ -15,7 +27,7 @@ install_command() {
get_concurrency() {
if which nproc > /dev/null 2>&1; then
echo $(nproc)
elif which sysctl > /dev/null 2>&1; then
elif which sysctl > /dev/null 2>&1 && sysctl hw.ncpu > /dev/null 2>&1; then
echo $(sysctl -n hw.ncpu)
elif [ -f /proc/cpuinfo ]; then
echo $(grep -c processor /proc/cpuinfo)
@ -64,7 +76,9 @@ install_tool_version() {
local install_path=$(get_install_path $plugin_name $install_type $version)
local concurrency=$(get_concurrency)
if [ -d $install_path ]; then
trap 'handle_cancel $install_path' INT
if [ -d "$install_path" ]; then
echo "$plugin_name $full_version is already installed"
else
(
@ -72,16 +86,15 @@ install_tool_version() {
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
export ASDF_CONCURRENCY=$concurrency
mkdir $install_path
bash ${plugin_path}/bin/install
mkdir "$install_path"
bash "${plugin_path}"/bin/install
)
local exit_code=$?
if [ $exit_code -eq 0 ]; then
reshim_command $plugin_name $full_version
else
rm -rf $install_path
exit 1
handle_failure "$install_path"
fi
fi
}

View File

@ -1,11 +1,24 @@
plugin_add_command() {
if [ "$#" -ne 2 ]; then
display_error "usage: asdf plugin-add <name> <git-url>"
if [[ $# -lt 1 || $# -gt 2 ]]; then
display_error "usage: asdf plugin-add <name> [<git-url>]"
exit 1
fi
local plugin_name=$1
local source_url=$2
if [ -n "$2" ]; then
local source_url=$2
else
initialize_or_update_repository
local source_url
source_url=$(get_plugin_source_url "$plugin_name")
fi
if [ -z "$source_url" ]; then
display_error "plugin $plugin_name not found in repository"
exit 1
fi
local plugin_path=$(get_plugin_path $plugin_name)
mkdir -p $(asdf_dir)/plugins

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}'
}

55
lib/commands/which.sh Normal file
View File

@ -0,0 +1,55 @@
current_version() {
local plugin_name=$1
check_if_plugin_exists $plugin_name
local search_path=$(pwd)
local version_and_path=$(find_version "$plugin_name" "$search_path")
local version=$(cut -d '|' -f 1 <<< "$version_and_path");
local version_file_path=$(cut -d '|' -f 2 <<< "$version_and_path");
check_if_version_exists $plugin_name $version
check_for_deprecated_plugin $plugin_name
if [ -z "$version" ]; then
echo "No version set for $plugin_name"
exit 1
else
echo "$version"
exit 0
fi
}
which_command() {
local plugin_name=$1
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_name
local install_type="version"
local install_path=$(get_install_path $plugin_name $install_type $(current_version $plugin_name))
if [ -d $install_path ]; then
echo $install_path/bin/$plugin_name
exit 0
else
echo "Version not installed"
exit 1
fi
}
# Warn if the plugin isn't using the updated legacy file api.
check_for_deprecated_plugin() {
local plugin_name=$1
local plugin_path=$(get_plugin_path "$plugin_name")
local legacy_config=$(get_asdf_config_value "legacy_version_file")
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
local new_script="${plugin_path}/bin/list-legacy-filenames"
if [ "$legacy_config" = "yes" ] && [ -f $deprecated_script ] && [ ! -f $new_script ]; then
echo "Heads up! It looks like your $plugin_name plugin is out of date. You can update it with:"
echo ""
echo " asdf plugin-update $plugin_name"
echo ""
fi
}

View File

@ -1,5 +1,14 @@
# 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"
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() {
@ -41,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
@ -52,17 +61,15 @@ 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
# if version starts with path: use that directory
if [ "${version/path:}" != "$version" ]; then
version_dir=$(echo $version | cut -d: -f 2)
fi
check_if_plugin_exists $plugin_name
if [ ! -d $version_dir ]; then
display_error "version $version is not installed for $plugin"
local install_path=$(find_install_path $plugin_name $version)
if [ "$version" != "system" ] && [ ! -d $install_path ]; then
display_error "version $version is not installed for $plugin_name"
exit 1
fi
}
@ -136,6 +143,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
@ -175,29 +230,61 @@ 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
}
asdf_repository_url() {
echo "https://github.com/asdf-vm/asdf-plugins.git"
}
initialize_or_update_repository() {
local repository_url
local repository_path
repository_url=$(asdf_repository_url)
repository_path=$(asdf_dir)/repository
if [ -d "$repository_path" ]; then
echo "updating plugin repository..."
(cd "$repository_path" && git fetch && git reset --hard origin/master)
else
echo "initializing plugin repository..."
git clone "$repository_url" "$repository_path"
fi
}
get_plugin_source_url() {
local plugin_name=$1
local plugin_config
plugin_config="$(asdf_dir)/repository/plugins/$plugin_name"
if [ -f "$plugin_config" ]; then
grep "repository" "$plugin_config" | awk -F'=' '{print $2}' | sed 's/ //'
fi
}

28
test/plugin_commands.bats Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-add.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh
setup() {
setup_asdf_dir
}
teardown() {
clean_asdf_dir
}
@test "plugin_add command with no URL specified adds a plugin using repo" {
run plugin_add_command "elixir"
[ "$status" -eq 0 ]
run plugin_list_command
[ "$output" = "elixir" ]
}
@test "plugin_add command with no URL specified fails if the plugin doesn't exist" {
run plugin_add_command "does-not-exist"
[ "$status" -eq 1 ]
echo "$output" | grep "plugin does-not-exist not found in repository"
}

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,25 @@ 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_version_exists should be ok for ref:version install" {
mkdir -p $ASDF_DIR/plugins/foo
mkdir -p $ASDF_DIR/installs/foo/ref-master
run check_if_version_exists "foo" "ref:master"
[ "$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 +154,46 @@ 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" ]
}
@test "get_executable_path for ref:version installed version should resolve to ref-version" {
mkdir -p $ASDF_DIR/plugins/foo
mkdir -p $ASDF_DIR/installs/foo/ref-master/bin
executable_path=$ASDF_DIR/installs/foo/ref-master/bin/dummy
touch $executable_path
chmod +x $executable_path
run get_executable_path "foo" "ref:master" "bin/dummy"
[ "$status" -eq 0 ]
[ "$output" = "$executable_path" ]
}

38
test/which_command.bats Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/which.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
setup() {
setup_asdf_dir
install_dummy_plugin
run install_command dummy 1.0
PROJECT_DIR=$HOME/project
mkdir $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
@test "which should show dummy 1.0 main binary path" {
cd $PROJECT_DIR
echo 'dummy 1.0' >> $PROJECT_DIR/.tool-versions
run current_version "dummy"
[ "$output" = "1.0" ]
run which_command "dummy"
[ "$status" -eq 0 ]
[ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ]
}
@test "which should error when the plugin doesn't exist" {
run which_command "foobar"
[ "$status" -eq 1 ]
[ "$output" = "No such plugin" ]
}