mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Add plugin-list-all command
This commit is contained in:
parent
29a29f196c
commit
b9fae70c0d
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
installs
|
||||
plugins
|
||||
/plugins
|
||||
shims
|
||||
repository
|
||||
.vagrant
|
||||
keyrings
|
||||
/tmp
|
||||
|
6
bin/asdf
6
bin/asdf
@ -15,6 +15,7 @@ source $(dirname $(dirname $0))/lib/commands/list-all.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/reshim.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-add.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-list.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-list-all.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
|
||||
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
|
||||
|
||||
@ -49,7 +50,7 @@ case $1 in
|
||||
|
||||
"which")
|
||||
which_command $callback_args;;
|
||||
|
||||
|
||||
"local")
|
||||
local_command $callback_args;;
|
||||
|
||||
@ -74,6 +75,9 @@ case $1 in
|
||||
"plugin-list")
|
||||
plugin_list_command $callback_args;;
|
||||
|
||||
"plugin-list-all")
|
||||
plugin_list_all_command $callback_args;;
|
||||
|
||||
"plugin-update")
|
||||
plugin_update_command $callback_args;;
|
||||
|
||||
|
9
lib/commands/plugin-list-all.sh
Normal file
9
lib/commands/plugin-list-all.sh
Normal file
@ -0,0 +1,9 @@
|
||||
plugin_list_all_command() {
|
||||
initialize_or_update_repository
|
||||
|
||||
local plugins_path=$(asdf_dir)/repository/plugins
|
||||
for plugin in $plugins_path/*; do
|
||||
local plugin_name="$(basename $plugin)"
|
||||
echo "$plugin_name"
|
||||
done
|
||||
}
|
19
lib/utils.sh
19
lib/utils.sh
@ -261,6 +261,14 @@ asdf_repository_url() {
|
||||
echo "https://github.com/asdf-vm/asdf-plugins.git"
|
||||
}
|
||||
|
||||
repository_needs_update() {
|
||||
local update_file_dir="$(asdf_dir)/tmp"
|
||||
local update_file_name="repo-updated"
|
||||
# `find` outputs filename if it has not been modified in the last day
|
||||
local find_result=$(find $update_file_dir -name "$update_file_name" -type f -mtime +1 -print)
|
||||
[ -n "$find_result" ]
|
||||
}
|
||||
|
||||
initialize_or_update_repository() {
|
||||
local repository_url
|
||||
local repository_path
|
||||
@ -268,13 +276,16 @@ initialize_or_update_repository() {
|
||||
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
|
||||
if [ ! -d "$repository_path" ]; then
|
||||
echo "initializing plugin repository..."
|
||||
git clone "$repository_url" "$repository_path"
|
||||
elif repository_needs_update; then
|
||||
echo "updating plugin repository..."
|
||||
(cd "$repository_path" && git fetch && git reset --hard origin/master)
|
||||
fi
|
||||
|
||||
mkdir -p "$(asdf_dir)/tmp"
|
||||
touch "$(asdf_dir)/tmp/repo-updated"
|
||||
}
|
||||
|
||||
get_plugin_source_url() {
|
||||
|
1
test/fixtures/dummy_plugins_repo/plugins/bar
vendored
Normal file
1
test/fixtures/dummy_plugins_repo/plugins/bar
vendored
Normal file
@ -0,0 +1 @@
|
||||
repository = http://example.com/bar
|
1
test/fixtures/dummy_plugins_repo/plugins/foo
vendored
Normal file
1
test/fixtures/dummy_plugins_repo/plugins/foo
vendored
Normal file
@ -0,0 +1 @@
|
||||
repository = http://example.com/foo
|
22
test/plugin_list_all_command.sh
Normal file
22
test/plugin_list_all_command.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helpers
|
||||
|
||||
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list-all.sh
|
||||
|
||||
setup() {
|
||||
setup_asdf_dir
|
||||
setup_repo
|
||||
}
|
||||
|
||||
teardown() {
|
||||
clean_asdf_dir
|
||||
}
|
||||
|
||||
@test "plugin_list_all list all plugins in the repository" {
|
||||
run plugin_list_all_command
|
||||
local expected="bar
|
||||
foo"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
@ -7,6 +7,7 @@ setup_asdf_dir() {
|
||||
mkdir -p $ASDF_DIR/plugins
|
||||
mkdir -p $ASDF_DIR/installs
|
||||
mkdir -p $ASDF_DIR/shims
|
||||
mkdir -p $ASDF_DIR/tmp
|
||||
PATH=$ASDF_DIR/shims:$PATH
|
||||
}
|
||||
|
||||
@ -33,3 +34,8 @@ clean_asdf_dir() {
|
||||
rm -rf $BASE_DIR
|
||||
unset ASDF_DIR
|
||||
}
|
||||
|
||||
setup_repo() {
|
||||
cp -r $BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo $ASDF_DIR/repository
|
||||
touch "$(asdf_dir)/tmp/repo-updated"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user