Skip to content

Commit 3217a1f

Browse files
committed
Merge and resolve conflicts
2 parents bcb4780 + 5f6cf27 commit 3217a1f

8 files changed

Lines changed: 77 additions & 57 deletions

File tree

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
> * [Ruby](https://github.com/HashNuke/asdf-ruby)
66
> * [Erlang](https://github.com/HashNuke/asdf-erlang)
77
> * [Elixir](https://github.com/HashNuke/asdf-elixir)
8+
> * Node.js pending. Tired polishing this stuff. I'll finish it up over the weekend.
89
>
910
> There is a [super-simple API](https://github.com/HashNuke/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
1011
@@ -84,6 +85,8 @@ asdf uninstall <name> <version>
8485
# asdf uninstall erlang 17.3
8586
```
8687

88+
*If a plugin supports downloading & compiling from source, you can also do this `ref:foo` (replace `foo` with the branch/tag/commit).* You'll have to use the same name when uninstalling too.
89+
8790
##### Lists installed versions
8891

8992
```bash
@@ -98,24 +101,24 @@ asdf list-all <name>
98101
# asdf list-all erlang
99102
```
100103

101-
##### Use a specific version of a package
102-
103-
```bash
104-
asdf use <name> <version>
105-
# asdf use erlang 17.5
106-
```
107-
108-
This will set the requested version of the package for the current terminal session.
109-
110104
## The `.tool-versions` file
111105

112-
Add a `.tool-versions` file to your project dir and versions of those packages will be used.
106+
Add a `.tool-versions` file to your project dir and versions of those tools will be used.
107+
**Global defaults can be set in the file `$HOME/.tool-versions`**
108+
109+
This is what a `.tool-versions` file looks like:
113110

114111
```
115-
elixir 1.0.2
116-
erlang 17.3
112+
ruby 2.2.0
113+
nodejs 0.12.3
117114
```
118115

116+
The versions can be in the following format:
117+
118+
* `0.12.3` - an actual version. Plugins that support downloading binaries, will download binaries.
119+
* `ref:v1.0.2-a` or `ref:39cb398vb39` - tag/commit/branch to download from github and compile
120+
* `path:/src/elixir` - a path to custom compiled version of a tool to use. For use by language developers and such.
121+
119122
## Credits
120123

121124
Me ([@HashNuke](http://github.com/HashNuke)), High-fever, cold, cough.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Different, old, new.
1010
So there came more version managers
1111
And many commands for them
1212

13-
> I installed a lot of them (rbenv, erlenv, exenv, nvm, etc)
13+
> I installed a lot of them
1414
I learnt a lot of commands
1515

1616
> Then I said, just one more version manager

bin/private/asdf-exec

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717

1818

1919
IFS=':' read -a version_info <<< "$full_version"
20-
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
20+
if [ "${version_info[0]}" = "ref" ]; then
2121
install_type="${version_info[0]}"
2222
version="${version_info[1]}"
2323
install_path=$(get_install_path $plugin_name $install_type $version)
@@ -58,11 +58,9 @@ if [ -f ${plugin_path}/bin/exec-env ]; then
5858
unset ASDF_INSTALL_PATH
5959

6060
${install_path}/${executable_path} "${@:3}"
61-
exit $?
6261
)
6362
else
6463
(
6564
${install_path}/${executable_path} "${@:3}"
66-
exit $?
6765
)
6866
fi

docs/creating-plugins.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,51 @@
11
## Creating plugins
22

3-
A plugin is a git repo, with a couple executable scripts, to support versioning another language or tool. These scripts are run when `list-all`, `install`, `uninstall` or `exec-env` commands are run. You can set or unset env vars and do anything required to setup the environment for the tool.
3+
A plugin is a git repo, with a couple executable scripts, to support versioning another language or tool. These scripts are run when `list-all`, `install` or `uninstall` commands are run. You can set or unset env vars and do anything required to setup the environment for the tool.
44

55
### Required scripts
66

77
* `bin/list-all` - lists all installable versions
88
* `bin/install` - installs the specified version
99

10-
##### bin/list-all
10+
11+
All scripts except `bin/list-all` will have access to the following env vars to act upon:
12+
13+
* `ASDF_INSTALL_TYPE` - `version` or `ref`
14+
* `ASDF_INSTALL_VERSION` - if `ASDF_INSTALL_TYPE` is `version` then this will be the version number. Else it will be the git ref that is passed. Might point to a tag/commit/branch on the repo.
15+
* `ASDF_INSTALL_PATH` - the dir where the it *has been* installed (or *should* be installed in case of the `bin/install` script)
16+
17+
18+
#### bin/list-all
1119

1220
Must print a string with a space-seperated list of versions. Example output would be the following:
1321

1422
```
1523
1.0.1 1.0.2 1.3.0 1.4
1624
```
1725

18-
##### bin/install
19-
20-
This script should install the package. It will be passed the following command-line args (in order).
26+
#### bin/install
2127

22-
* *install type* - "version", "tag", "commit"
23-
* *version* - this is the version or commit sha or the tag name that should be installed (use the first argument to figure out what to do).
24-
* *install path* - the dir where the it *should* be installed
28+
This script should install the version, in the path mentioned in `ASDF_INSTALL_PATH`
2529

2630

2731
### Optional scripts
2832

29-
* `bin/list-bin-paths` - list executables for the version of the package
30-
* `bin/exec-env` - `echo` a space separated list of "key1=value1 key2=value2" and asdf will set them before running your command
31-
* `bin/uninstall` - uninstalls the specified version
32-
33+
#### bin/list-bin-paths
3334

34-
##### bin/list-bin-paths
35-
36-
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:
35+
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:
3736

3837
```
3938
bin tools veggies
4039
```
4140

42-
Shims will be automatically created for each of the binaries/executables. If this script is not specified, asdf will look for the `bin` dir in an installation and create shims for those.
43-
44-
##### bin/exec-env
45-
46-
Will be passed the following args
41+
This will instruct asdf to create shims for the files in `<install-path>/bin`, `<install-path>/tools` and `<install-path>/veggies`
4742

48-
* *install type*
49-
* *version*
43+
If this script is not specified, asdf will look for the `bin` dir in an installation and create shims for those.
5044

51-
Must print a string with space-seperated list of env vars to set. Example output would be
45+
#### bin/exec-env
5246

53-
```
54-
FOO=bar BAR=baz XYZ=123
55-
```
47+
Setup the env to run the binaries in the package.
5648

57-
##### bin/uninstall
49+
#### bin/uninstall
5850

59-
Uninstalls a specific version of a tool. Same args as the `bin/install` script.
51+
Uninstalls a specific version of a tool.

lib/commands/install.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
install_command() {
2-
local package_name=$1
2+
local plugin_name=$1
33
local full_version=$2
4-
local plugin_path=$(get_plugin_path $package_name)
4+
local plugin_path=$(get_plugin_path $plugin_name)
55
check_if_plugin_exists $plugin_path
66

77
IFS=':' read -a version_info <<< "$full_version"
8-
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
8+
if [ "${version_info[0]}" = "ref" ]; then
99
local install_type="${version_info[0]}"
1010
local version="${version_info[1]}"
1111
else
1212
local install_type="version"
1313
local version="${version_info[0]}"
1414
fi
1515

16-
local install_path=$(get_install_path $package_name $install_type $version)
17-
${plugin_path}/bin/install $install_type $version $install_path
18-
reshim_command $package_name $full_version
16+
local install_path=$(get_install_path $plugin_name $install_type $version)
17+
if [ -d $install_path ]; then
18+
echo "$plugin_name $full_version is already installed"
19+
echo "To uninstall it run: asdf uninstall $plugin_name $full_version"
20+
exit 1
21+
fi
22+
23+
(
24+
export ASDF_INSTALL_TYPE=$install_type
25+
export ASDF_INSTALL_VERSION=$version
26+
export ASDF_INSTALL_PATH=$install_path
27+
bash ${plugin_path}/bin/install
28+
)
29+
local exit_code=$?
30+
if [ $exit_code -eq 0 ]; then
31+
reshim_command $plugin_name $full_version
32+
else
33+
exit $exit_code
34+
fi
1935
}

lib/commands/list-all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ list_all_command() {
22
local package_name=$1
33
local plugin_path=$(get_plugin_path $package_name)
44
check_if_plugin_exists $plugin_path
5-
local versions=$( ${plugin_path}/bin/list-all )
5+
6+
local versions=$(bash ${plugin_path}/bin/list-all)
67

78
IFS=' ' read -a versions_list <<< "$versions"
89

lib/commands/reshim.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reshim_command() {
2323
local package_installs_path=$(asdf_dir)/installs/${plugin_name}
2424

2525
for install in ${package_installs_path}/*/; do
26-
local full_version_name=$(echo $(basename $install) | sed 's/tag\-/tag\:/' | sed 's/commit-/commit:/')
26+
local full_version_name=$(echo $(basename $install) | sed 's/ref\-/ref\:/')
2727
generate_shims_for_version $plugin_name $full_version_name
2828
done
2929
fi
@@ -59,7 +59,7 @@ generate_shim_for_executable() {
5959
check_if_plugin_exists $plugin_path
6060

6161
IFS=':' read -a version_info <<< "$full_version"
62-
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
62+
if [ "${version_info[0]}" = "ref" ]; then
6363
local install_type="${version_info[0]}"
6464
local version="${version_info[1]}"
6565
else
@@ -78,7 +78,7 @@ generate_shims_for_version() {
7878
check_if_plugin_exists $plugin_path
7979

8080
IFS=':' read -a version_info <<< "$full_version"
81-
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
81+
if [ "${version_info[0]}" = "ref" ]; then
8282
local install_type="${version_info[0]}"
8383
local version="${version_info[1]}"
8484
else
@@ -89,7 +89,12 @@ generate_shims_for_version() {
8989
local install_path=$(get_install_path $package_name $install_type $version)
9090

9191
if [ -f ${plugin_path}/bin/list-bin-paths ]; then
92-
local space_seperated_list_of_bin_paths=$(sh ${plugin_path}/bin/list-bin-paths $package_name $install_type $version "${@:2}")
92+
local space_seperated_list_of_bin_paths=$(
93+
export ASDF_INSTALL_TYPE=$install_type
94+
export ASDF_INSTALL_VERSION=$version
95+
export ASDF_INSTALL_PATH=$install_path
96+
bash ${plugin_path}/bin/list-bin-paths
97+
)
9398
else
9499
local space_seperated_list_of_bin_paths="bin"
95100
fi

lib/commands/uninstall.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ uninstall_command() {
66
check_if_plugin_exists $plugin_path
77

88
IFS=':' read -a version_info <<< "$full_version"
9-
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
9+
if [ "${version_info[0]}" = "ref" ]; then
1010
local install_type="${version_info[0]}"
1111
local version="${version_info[1]}"
1212
else
@@ -22,7 +22,12 @@ uninstall_command() {
2222
fi
2323

2424
if [ -f ${plugin_path}/bin/uninstall ]; then
25-
${plugin_path}/bin/uninstall $install_type $version $install_path "${@:3}"
25+
(
26+
export ASDF_INSTALL_TYPE=$install_type
27+
export ASDF_INSTALL_VERSION=$version
28+
export ASDF_INSTALL_PATH=$install_path
29+
bash ${plugin_path}/bin/uninstall
30+
)
2631
else
2732
rm -rf $install_path
2833
fi

0 commit comments

Comments
 (0)