Merge branch 'master' of github.com:HashNuke/asdf

This commit is contained in:
Akash Manohar J 2015-05-18 06:55:46 +05:30
commit a1d43f524d
17 changed files with 132 additions and 130 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
installs
sources
plugins
shims

View File

@ -8,9 +8,9 @@ source $(dirname $(dirname $0))/lib/commands/uninstall.sh
source $(dirname $(dirname $0))/lib/commands/list.sh
source $(dirname $(dirname $0))/lib/commands/list-all.sh
source $(dirname $(dirname $0))/lib/commands/reshim.sh
source $(dirname $(dirname $0))/lib/commands/source-add.sh
source $(dirname $(dirname $0))/lib/commands/source-update.sh
source $(dirname $(dirname $0))/lib/commands/source-remove.sh
source $(dirname $(dirname $0))/lib/commands/plugin-add.sh
source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
callback_args="${@:2}"
@ -38,14 +38,14 @@ case $1 in
"reshim")
reshim_command $callback_args;;
"source-add")
source_add_command $callback_args;;
"plugin-add")
plugin_add_command $callback_args;;
"source-update")
source_update_command $callback_args;;
"plugin-update")
plugin_update_command $callback_args;;
"source-remove")
source_remove_command $callback_args;;
"plugin-remove")
plugin_remove_command $callback_args;;
*)
help_command

View File

@ -5,8 +5,8 @@ source $(dirname $(dirname $(dirname $0)))/lib/utils.sh
package=$1
executable_path=$2
source_path=$(get_source_path $package)
check_if_source_exists $source_path
plugin_path=$(get_plugin_path $package)
check_if_plugin_exists $plugin_path
full_version=$(get_preset_version_for $package)
@ -27,8 +27,8 @@ fi
install_path=$(get_install_path $package $install_type $version)
if [ -f ${source_path}/bin/exec-env ]; then
exec_env=$(${source_path}/bin/exec-env $install_type $version $install_path)
if [ -f ${plugin_path}/bin/exec-env ]; then
exec_env=$(${plugin_path}/bin/exec-env $install_type $version $install_path)
(
eval export ${exec_env};
${install_path}/${executable_path} "${@:3}"

View File

@ -1,59 +0,0 @@
## Creating package sources
A package source is a git repo, with the following executable scripts
* `bin/list-all` - lists all installable versions
* `bin/install` - installs the specified version
* `bin/list-executables` - list executables for the version of the package
##### Options scripts
* `bin/exec-env` - whatever you want to run when a specific version is used (like set an env var?)
* `bin/uninstall` - uninstalls the specified version
### bin/list-all
Must print a string with a space-seperated list of versions. Example output would be the following:
```
1.0.1 1.0.2 1.3.0 1.4
```
### bin/install
This script should install the package. It will be passed the following command-line args (in order).
* *install type* - "version", "tag", "commit"
* *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).
* *install path* - the dir where the it *should* be installed
If you need to provide any options, use environment variables.
These scripts are run when `list-all`, `install`, `uninstall` or `exec-env` commands are run. You can set or unset env vars and do whatever you need.
### bin/list-executables
Must print a string with a space-seperated list of paths to executables. The paths must be relative to the install path passed. Example output would be:
```
bin/abc bin/xyz scripts/jkl
```
### bin/exec-env
Will be passed the following args
* *install type*
* *version*
Must print a string with space-seperated list of env vars to set. Example output would be
### bin/uninstall
Uninstalls a command. Same args as the `bin/install` script.
```
FOO=123 BAR=xyz BAZ=example
```
-------------

55
docs/creating-plugins.md Normal file
View File

@ -0,0 +1,55 @@
## Creating package sources
A package source is a git repo, with a couple executable scripts. 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.
### Required scripts
* `bin/list-all` - lists all installable versions
* `bin/install` - installs the specified version
##### bin/list-all
Must print a string with a space-seperated list of versions. Example output would be the following:
```
1.0.1 1.0.2 1.3.0 1.4
```
##### bin/install
This script should install the package. It will be passed the following command-line args (in order).
* *install type* - "version", "tag", "commit"
* *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).
* *install path* - the dir where the it *should* be installed
### Optional scripts
* `bin/list-bin-paths` - list executables for the version of the package
* `bin/exec-env` - `echo` a space separated list of "key1=value1 key2=value2" and asdf will set them before running your command
* `bin/uninstall` - uninstalls the specified version
##### bin/list-bin-paths
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:
```
bin tools veggies
```
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.
##### bin/exec-env
Will be passed the following args
* *install type*
* *version*
Must print a string with space-seperated list of env vars to set. Example output would be
##### bin/uninstall
Uninstalls a specific version of a tool. Same args as the `bin/install` script.

View File

@ -1,8 +1,8 @@
install_command() {
local package_name=$1
local full_version=$2
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
@ -14,6 +14,6 @@ install_command() {
fi
local install_path=$(get_install_path $package_name $install_type $version)
${source_path}/bin/install $install_type $version $install_path
${plugin_path}/bin/install $install_type $version $install_path
reshim_command $package_name $full_version
}

View File

@ -1,8 +1,8 @@
list_all_command() {
local package_name=$1
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
local versions=$( ${source_path}/bin/list-all )
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
local versions=$( ${plugin_path}/bin/list-all )
IFS=' ' read -a versions_list <<< "$versions"

View File

@ -1,7 +1,7 @@
list_command() {
local package_name=$1
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
local package_installs_path=$(asdf_dir)/installs/${package_name}

View File

@ -0,0 +1,11 @@
plugin_add_command() {
local package_name=$1
local source_url=$2
local plugin_path=$(get_plugin_path $package_name)
mkdir -p $(asdf_dir)/plugins
git clone $source_url $plugin_path
if [ $? -eq 0 ]; then
chmod +x $plugin_path/bin/*
fi
}

View File

@ -0,0 +1,7 @@
plugin_remove_command() {
local package_name=$1
local plugin_path=$(get_plugin_path $package_name)
rm -rf $plugin_path
rm -rf $(asdf_dir)/installs/${package_name}
}

View File

@ -0,0 +1,12 @@
plugin_update_command() {
local package_name=$1
if [ "$package_name" = "--all" ]; then
for dir in $(asdf_dir)/plugins/*; do
(cd "$dir" && git pull)
done
else
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
(cd $plugin_path; git pull)
fi
}

View File

@ -2,8 +2,8 @@ reshim_command() {
local package_name=$1
local full_version=$2
local executable_path=$3
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
ensure_shims_dir
# If full version is empty then generate shims for all versions in the package
@ -41,7 +41,7 @@ write_shim_script() {
local shim_path=$(asdf_dir)/shims/$(basename $executable_path)
echo """#!/usr/bin/env sh
$(asdf_dir)/bin/private/asdf-exec ${package_name} ${executable_path} "\$@"
$(asdf_dir)/bin/private/asdf-exec ${package_name} ${executable_path} \"\$@\"
""" > $shim_path
chmod +x $shim_path
@ -52,9 +52,9 @@ generate_shim_for_executable() {
local package_name=$1
local full_version=$2
local executable=$3
local source_path=$(get_source_path $package_name)
local plugin_path=$(get_plugin_path $package_name)
check_if_source_exists $source_path
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
@ -72,8 +72,8 @@ generate_shim_for_executable() {
generate_shims_for_version() {
local package_name=$1
local full_version=$2
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
local plugin_path=$(get_plugin_path $package_name)
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
@ -86,7 +86,12 @@ generate_shims_for_version() {
local install_path=$(get_install_path $package_name $install_type $version)
local space_seperated_list_of_bin_paths=$(sh ${source_path}/bin/list-bin-paths $package_name $install_type $version "${@:2}")
if [ -f ${plugin_path}/bin/list-bin-paths ]; then
local space_seperated_list_of_bin_paths=$(sh ${plugin_path}/bin/list-bin-paths $package_name $install_type $version "${@:2}")
else
local space_seperated_list_of_bin_paths="bin"
fi
IFS=' ' read -a all_bin_paths <<< "$space_seperated_list_of_bin_paths"
for bin_path in "${all_bin_paths[@]}"; do

View File

@ -1,11 +0,0 @@
source_add_command() {
local package_name=$1
local source_url=$2
local source_path=$(get_source_path $package_name)
mkdir -p $(asdf_dir)/sources
git clone $source_url $source_path
if [ $? -eq 0 ]; then
chmod +x $source_path/bin/*
fi
}

View File

@ -1,7 +0,0 @@
source_remove_command() {
local package_name=$1
local source_path=$(get_source_path $package_name)
rm -rf $source_path
rm -rf $(asdf_dir)/installs/${package_name}
}

View File

@ -1,12 +0,0 @@
source_update_command() {
local package_name=$1
if [ "$package_name" = "--all" ]; then
for dir in $(asdf_dir)/sources/*; do
(cd "$dir" && git pull)
done
else
local source_path=$(get_source_path $package_name)
check_if_source_exists $source_path
(cd $source_path; git pull)
fi
}

View File

@ -1,9 +1,9 @@
uninstall_command() {
local package_name=$1
local full_version=$2
local source_path=$(get_source_path $package_name)
local plugin_path=$(get_plugin_path $package_name)
check_if_source_exists $source_path
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]; then
@ -21,8 +21,8 @@ uninstall_command() {
exit 1
fi
if [ -f ${source_path}/bin/uninstall ]; then
${source_path}/bin/uninstall $install_type $version $install_path "${@:3}"
if [ -f ${plugin_path}/bin/uninstall ]; then
${plugin_path}/bin/uninstall $install_type $version $install_path "${@:3}"
else
rm -rf $install_path
fi

View File

@ -28,10 +28,10 @@ get_install_path() {
}
check_if_source_exists() {
check_if_plugin_exists() {
if [ ! -d $1 ]
then
display_error "No such package"
display_error "No such plugin"
exit 1
fi
}
@ -43,8 +43,8 @@ get_version_part() {
}
get_source_path() {
echo $(asdf_dir)/sources/$1
get_plugin_path() {
echo $(asdf_dir)/plugins/$1
}
@ -58,16 +58,16 @@ get_asdf_versions_file_path() {
local search_path=$(pwd)
while [ "$search_path" != "/" ]; do
if [ -f "$search_path/.asdf-versions" ]; then
asdf_tool_versions_path="$search_path/.asdf-versions"
if [ -f "$search_path/.tool-versions" ]; then
asdf_tool_versions_path="$search_path/.tool-versions"
break
fi
search_path=$(dirname $search_path)
done
if [ $asdf_tool_versions_path = "" ]; then
asdf_tool_versions_path=$HOME/.asdf-versions
if [ "$asdf_tool_versions_path" = "" ]; then
asdf_tool_versions_path=$HOME/.tool-versions
if [ ! -f $asdf_tool_versions_path ]; then
touch $asdf_tool_versions_path
fi