mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Improvements to asdf plugin
commands.
This commit is contained in:
parent
a64f94dacc
commit
3d3595c7a3
21
CHANGELOG.md
21
CHANGELOG.md
@ -4,6 +4,27 @@
|
||||
|
||||
Features
|
||||
|
||||
* Improve output format of `asdf plugin list all`
|
||||
|
||||
Long plugin names were causing problems with how we used printf.
|
||||
Now we use the `column` command to properly render output.
|
||||
|
||||
* Now `asdf plugin list` can take both `--urls` and `--refs` options.
|
||||
|
||||
When `--url` is used, we print the plugin's remote origin URL.
|
||||
While `--refs` prints the git branch/commit the plugin is at.
|
||||
|
||||
* It's now possible to update a plugin to an specific branch/commit.
|
||||
|
||||
`git plugin update <name> [git-ref]`
|
||||
|
||||
Checkouts a plugin to the specified `git-ref`. Defaults to `master`
|
||||
|
||||
* Now the `asdf plugin test` command can be specified with a plugin commit/branch to test.
|
||||
|
||||
This will help CI checks to actually test the commit they are running for.
|
||||
Previously we always used the plugin's `master` branch.
|
||||
|
||||
* Subcommand CLI support.
|
||||
|
||||
Users familiar with sub-command aware tools like `git` can now
|
||||
|
@ -1,15 +1,15 @@
|
||||
## Manage Plugins
|
||||
|
||||
| Command | Effect |
|
||||
| ------------------------------------ | ------------------------------------------------------------ |
|
||||
| `asdf plugin add <name> [<git-url>]` | Add a plugin from the plugin repo OR, add a Git repo |
|
||||
| | ...as a plugin by specifying the name and repo url |
|
||||
| `asdf plugin list` | List installed plugins |
|
||||
| `asdf plugin list --urls` | List installed plugins with repository URLs |
|
||||
| `asdf plugin list all` | List plugins registered on asdf-plugins repository with URLs |
|
||||
| `asdf plugin remove <name>` | Remove plugin and package versions |
|
||||
| `asdf plugin update <name>` | Update plugin |
|
||||
| `asdf plugin update --all` | Update all plugins |
|
||||
| Command | Effect |
|
||||
| -----------------------------------------| ------------------------------------------------------------ |
|
||||
| `asdf plugin add <name> [<git-url>]` | Add a plugin from the plugin repo OR, add a Git repo |
|
||||
| | ...as a plugin by specifying the name and repo url |
|
||||
| `asdf plugin list` | List installed plugins |
|
||||
| `asdf plugin list [--urls] [--refs]` | List installed plugins. Optionally show git urls and git-ref |
|
||||
| `asdf plugin list all` | List plugins registered on asdf-plugins repository with URLs |
|
||||
| `asdf plugin remove <name>` | Remove plugin and package versions |
|
||||
| `asdf plugin update <name> [<git-ref>]` | Update plugin to latest commit or a particular git ref. |
|
||||
| `asdf plugin update --all` | Update all plugins |
|
||||
|
||||
## Manage Packages
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
| `asdf global <name> <version>` | Set the package global version |
|
||||
| `asdf latest <name> [<version>]` | Show latest stable version of a package |
|
||||
| `asdf list <name>` | List installed versions of a package |
|
||||
| `asdf list-all <name> [<version>]` | List all versions of a package and optionally filter the returned versions |
|
||||
| `asdf list all <name> [<version>]` | List all versions of a package and optionally filter the returned versions |
|
||||
|
||||
## Utils
|
||||
|
||||
|
@ -141,17 +141,21 @@ This must be used wisely. For now AFAIK, it's only being used in the Elixir plug
|
||||
`asdf` contains the `plugin-test` command to test your plugin. You can use it as follows
|
||||
|
||||
```sh
|
||||
asdf plugin test <plugin-name> <plugin-url> [test-command] [--asdf-tool-version version]
|
||||
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]
|
||||
```
|
||||
|
||||
The two first arguments are required. The second two arguments are optional. The third is a command can also be passed to check it runs correctly. For example to test the NodeJS plugin, we could run
|
||||
Only the two first arguments are required.
|
||||
If __version_ is specified, the tool will be installed with that specific version. Defaults to whatever returns `asdf latest <plugin-name>`.
|
||||
If _git-ref_ is specified, the plugin itself is checked out at that commit/branch/tag, useful for testing a pull-request on your plugin's CI.
|
||||
|
||||
Rest arguments are considered the command to execute to ensure the installed tool works correctly.
|
||||
Normally it would be something that takes `--version` or `--help`.
|
||||
For example, to test the NodeJS plugin, we could run
|
||||
|
||||
```sh
|
||||
asdf plugin test nodejs https://github.com/asdf-vm/asdf-nodejs.git 'node --version'
|
||||
asdf plugin test nodejs https://github.com/asdf-vm/asdf-nodejs.git node --version
|
||||
```
|
||||
|
||||
The fourth is a tool version that can be specified if you want the test to install a specific version of the tool. This can be useful if not all versions are compatible with all the operating systems you are testing on. If you do not specify a version the last version in the `list-all` output will be used.
|
||||
|
||||
We strongly recommend you test your plugin on TravisCI, to make sure it works on both Linux and OSX.
|
||||
|
||||
Here is a sample `.travis.yml` file, customize it to your needs
|
||||
|
53
help.txt
53
help.txt
@ -1,34 +1,33 @@
|
||||
MANAGE PLUGINS
|
||||
asdf plugin add <name> [<git-url>] Add a plugin from the plugin repo OR, add a Git repo
|
||||
as a plugin by specifying the name and repo url
|
||||
asdf plugin list List installed plugins
|
||||
asdf plugin list --urls List installed plugins with repository URLs
|
||||
asdf plugin list all List plugins registered on asdf-plugins repository with URLs
|
||||
asdf plugin remove <name> Remove plugin and package versions
|
||||
asdf plugin update <name> Update plugin
|
||||
asdf plugin update --all Update all plugins
|
||||
asdf plugin add <name> [<git-url>] Add a plugin from the plugin repo OR, add a Git repo
|
||||
as a plugin by specifying the name and repo url
|
||||
asdf plugin list [--urls] [--refs] List installed plugins. Optionally show git urls and git-ref.
|
||||
asdf plugin list all List plugins registered on asdf-plugins repository with URLs
|
||||
asdf plugin remove <name> Remove plugin and package versions
|
||||
asdf plugin update <name> [<git-ref>] Update a plugin to latest commit or a particular git-ref.
|
||||
asdf plugin update --all Update all plugins
|
||||
|
||||
|
||||
MANAGE PACKAGES
|
||||
asdf install [<name> <version>] Install a specific version of a package or,
|
||||
with no arguments, install all the package
|
||||
versions listed in the .tool-versions file
|
||||
asdf uninstall <name> <version> Remove a specific version of a package
|
||||
asdf current Display current version set or being used for all packages
|
||||
asdf current <name> Display current version set or being used for package
|
||||
asdf where <name> [<version>] Display install path for an installed or current version
|
||||
asdf which <command> Display the path to an executable
|
||||
asdf shell <name> <version> Set the package version in the current shell
|
||||
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
|
||||
asdf list all <name> List all versions of a package
|
||||
asdf install [<name> <version>] Install a specific version of a package or,
|
||||
with no arguments, install all the package
|
||||
versions listed in the .tool-versions file
|
||||
asdf uninstall <name> <version> Remove a specific version of a package
|
||||
asdf current Display current version set or being used for all packages
|
||||
asdf current <name> Display current version set or being used for package
|
||||
asdf where <name> [<version>] Display install path for an installed or current version
|
||||
asdf which <command> Display the path to an executable
|
||||
asdf shell <name> <version> Set the package version in the current shell
|
||||
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
|
||||
asdf list all <name> List all versions of a package
|
||||
|
||||
|
||||
UTILS
|
||||
asdf exec <command> [args..] Executes the command shim for current version
|
||||
asdf env <command> [util] Runs util (default: `env`) inside the environment used for command shim execution.
|
||||
asdf reshim <name> <version> Recreate shims for version of a package
|
||||
asdf shim-versions <command> List on which plugins and versions is command available
|
||||
asdf update Update asdf to the latest stable release
|
||||
asdf update --head Update asdf to the latest on the master branch
|
||||
asdf exec <command> [args..] Executes the command shim for current version
|
||||
asdf env <command> [util] Runs util (default: `env`) inside the environment used for command shim execution.
|
||||
asdf reshim <name> <version> Recreate shims for version of a package
|
||||
asdf shim-versions <command> List on which plugins and versions is command available
|
||||
asdf update Update asdf to the latest stable release
|
||||
asdf update --head Update asdf to the latest on the master branch
|
||||
|
@ -1,37 +1,53 @@
|
||||
# -*- sh -*-
|
||||
|
||||
plugin_list_command() {
|
||||
local flag=$1
|
||||
local plugins_path
|
||||
plugins_path=$(get_plugin_path)
|
||||
|
||||
# 0 || 1 with flag
|
||||
if [ $# -eq 0 ] || { [ $# -eq 1 ] && [ "$flag" = "--urls" ]; }; then
|
||||
# valid command
|
||||
local show_repo
|
||||
local show_ref
|
||||
|
||||
local plugins_path
|
||||
plugins_path=$(get_plugin_path)
|
||||
while [ -n "$*" ]; do
|
||||
case "$1" in
|
||||
"--urls")
|
||||
show_repo=true
|
||||
shift
|
||||
;;
|
||||
"--refs")
|
||||
show_ref=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ls "$plugins_path" &>/dev/null; then
|
||||
if ls "$plugins_path" &>/dev/null; then
|
||||
(
|
||||
for plugin_path in "$plugins_path"/*; do
|
||||
plugin_name=$(basename "$plugin_path")
|
||||
printf "%s" "$plugin_name"
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
printf "%s\\n" "$plugin_name"
|
||||
else
|
||||
source_url=$(get_plugin_source_url "$plugin_name")
|
||||
printf "%-15s %s\\n" "$plugin_name" "$source_url"
|
||||
if [ -n "$show_repo" ]; then
|
||||
printf "\\t%s" "$(git --git-dir "$plugin_path/.git" remote get-url origin 2>/dev/null)"
|
||||
fi
|
||||
|
||||
done
|
||||
else
|
||||
display_error 'Oohes nooes ~! No plugins installed'
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$show_ref" ]; then
|
||||
local branch
|
||||
local gitref
|
||||
branch=$(git --git-dir "$plugin_path/.git" rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
gitref=$(git --git-dir "$plugin_path/.git" rev-parse --short HEAD 2>/dev/null)
|
||||
printf "\\t%s\\t%s" "$branch" "$gitref"
|
||||
fi
|
||||
|
||||
printf "\\n"
|
||||
done
|
||||
) | column -t -s $'\t'
|
||||
else
|
||||
display_error "usage: asdf plugin-list [--urls]"
|
||||
display_error 'Oohes nooes ~! No plugins installed'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
plugin_list_command "$@"
|
||||
|
@ -10,15 +10,17 @@ plugin_list_all_command() {
|
||||
plugins_local_path="$(get_plugin_path)"
|
||||
|
||||
if ls "$plugins_index_path" &>/dev/null; then
|
||||
for index_plugin in "$plugins_index_path"/*; do
|
||||
index_plugin_name=$(basename "$index_plugin")
|
||||
source_url=$(get_plugin_source_url "$index_plugin_name")
|
||||
installed_flag=""
|
||||
(
|
||||
for index_plugin in "$plugins_index_path"/*; do
|
||||
index_plugin_name=$(basename "$index_plugin")
|
||||
source_url=$(get_plugin_source_url "$index_plugin_name")
|
||||
installed_flag=" "
|
||||
|
||||
[[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*'
|
||||
[[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*'
|
||||
|
||||
printf "%-15s %-1s%s\\n" "$index_plugin_name" "$installed_flag" "$source_url"
|
||||
done
|
||||
printf "%s\\t%s\\n" "$index_plugin_name" "$installed_flag$source_url"
|
||||
done
|
||||
) | column -t -s $'\t'
|
||||
else
|
||||
printf "%s%s\\n" "error: index of plugins not found at " "$plugins_index_path"
|
||||
fi
|
||||
|
@ -6,14 +6,20 @@ plugin_test_command() {
|
||||
local plugin_url=$2
|
||||
local plugin_command_array=()
|
||||
local plugin_command
|
||||
local plugin_gitref="origin/master"
|
||||
local tool_version
|
||||
# shellcheck disable=SC2086
|
||||
set -- ${*:3}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--asdf-plugin-gitref)
|
||||
plugin_gitref="$2"
|
||||
shift # past flag
|
||||
shift # past value
|
||||
;;
|
||||
--asdf-tool-version)
|
||||
tool_version=$2
|
||||
tool_version="$2"
|
||||
shift # past flag
|
||||
shift # past value
|
||||
;;
|
||||
@ -59,6 +65,10 @@ plugin_test_command() {
|
||||
fail_test "$plugin_name was not properly installed"
|
||||
fi
|
||||
|
||||
if ! (asdf plugin-update "$plugin_name" "$plugin_gitref" >/dev/null); then
|
||||
fail_test "failed to checkout $plugin_name gitref: $plugin_gitref"
|
||||
fi
|
||||
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
local list_all="$plugin_path/bin/list-all"
|
||||
@ -77,7 +87,7 @@ plugin_test_command() {
|
||||
# test for most common token names we have on plugins. If both are empty show this warning
|
||||
if [ -z "$OAUTH_TOKEN" ] && [ -z "$GITHUB_API_TOKEN" ]; then
|
||||
echo "$plugin_name/bin/list-all is using GitHub API, just be sure you provide an API Authorization token"
|
||||
echo "via your travis settings. This is the current rate_limit:"
|
||||
echo "via your CI env GITHUB_API_TOKEN. This is the current rate_limit:"
|
||||
echo
|
||||
curl -s https://api.github.com/rate_limit
|
||||
echo
|
||||
|
@ -2,22 +2,23 @@
|
||||
|
||||
plugin_update_command() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
display_error "usage: asdf plugin-update {<name> | --all}"
|
||||
display_error "usage: asdf plugin-update {<name> | --all} [git-ref]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local plugin_name=$1
|
||||
local plugin_name="$1"
|
||||
local gitref="${2:-master}"
|
||||
if [ "$plugin_name" = "--all" ]; then
|
||||
for dir in "$(asdf_data_dir)"/plugins/*; do
|
||||
echo "Updating $(basename "$dir")..."
|
||||
(cd "$dir" && git pull)
|
||||
(cd "$dir" && git fetch -p -u origin "$gitref:$gitref" && git checkout -f "$gitref")
|
||||
done
|
||||
else
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
plugin_path="$(get_plugin_path "$plugin_name")"
|
||||
check_if_plugin_exists "$plugin_name"
|
||||
echo "Updating $plugin_name..."
|
||||
(cd "$plugin_path" && git pull)
|
||||
(cd "$plugin_path" && git fetch -p -u origin "$gitref:$gitref" && git checkout -f "$gitref")
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,11 @@ check_if_version_exists() {
|
||||
}
|
||||
|
||||
get_plugin_path() {
|
||||
echo "$(asdf_data_dir)/plugins/$1"
|
||||
if test -n "$1"; then
|
||||
echo "$(asdf_data_dir)/plugins/$1"
|
||||
else
|
||||
echo "$(asdf_data_dir)/plugins"
|
||||
fi
|
||||
}
|
||||
|
||||
display_error() {
|
||||
|
@ -14,9 +14,10 @@ teardown() {
|
||||
|
||||
@test "plugin_list_all list all plugins in the repository" {
|
||||
run asdf plugin-list-all
|
||||
local expected="bar http://example.com/bar
|
||||
dummy *http://example.com/dummy
|
||||
foo http://example.com/foo"
|
||||
local expected="\
|
||||
bar http://example.com/bar
|
||||
dummy *http://example.com/dummy
|
||||
foo http://example.com/foo"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user