Add plugin-list-all command

This commit is contained in:
Daniel Perez 2017-08-25 11:29:23 +09:00
parent 29a29f196c
commit b9fae70c0d
8 changed files with 61 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,6 +1,7 @@
installs installs
plugins /plugins
shims shims
repository repository
.vagrant .vagrant
keyrings keyrings
/tmp

View File

@ -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/reshim.sh
source $(dirname $(dirname $0))/lib/commands/plugin-add.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.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-update.sh
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
@ -49,7 +50,7 @@ case $1 in
"which") "which")
which_command $callback_args;; which_command $callback_args;;
"local") "local")
local_command $callback_args;; local_command $callback_args;;
@ -74,6 +75,9 @@ case $1 in
"plugin-list") "plugin-list")
plugin_list_command $callback_args;; plugin_list_command $callback_args;;
"plugin-list-all")
plugin_list_all_command $callback_args;;
"plugin-update") "plugin-update")
plugin_update_command $callback_args;; plugin_update_command $callback_args;;

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

View File

@ -261,6 +261,14 @@ asdf_repository_url() {
echo "https://github.com/asdf-vm/asdf-plugins.git" 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() { initialize_or_update_repository() {
local repository_url local repository_url
local repository_path local repository_path
@ -268,13 +276,16 @@ initialize_or_update_repository() {
repository_url=$(asdf_repository_url) repository_url=$(asdf_repository_url)
repository_path=$(asdf_dir)/repository repository_path=$(asdf_dir)/repository
if [ -d "$repository_path" ]; then if [ ! -d "$repository_path" ]; then
echo "updating plugin repository..."
(cd "$repository_path" && git fetch && git reset --hard origin/master)
else
echo "initializing plugin repository..." echo "initializing plugin repository..."
git clone "$repository_url" "$repository_path" 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 fi
mkdir -p "$(asdf_dir)/tmp"
touch "$(asdf_dir)/tmp/repo-updated"
} }
get_plugin_source_url() { get_plugin_source_url() {

View File

@ -0,0 +1 @@
repository = http://example.com/bar

View File

@ -0,0 +1 @@
repository = http://example.com/foo

View 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" ]
}

View File

@ -7,6 +7,7 @@ setup_asdf_dir() {
mkdir -p $ASDF_DIR/plugins mkdir -p $ASDF_DIR/plugins
mkdir -p $ASDF_DIR/installs mkdir -p $ASDF_DIR/installs
mkdir -p $ASDF_DIR/shims mkdir -p $ASDF_DIR/shims
mkdir -p $ASDF_DIR/tmp
PATH=$ASDF_DIR/shims:$PATH PATH=$ASDF_DIR/shims:$PATH
} }
@ -33,3 +34,8 @@ clean_asdf_dir() {
rm -rf $BASE_DIR rm -rf $BASE_DIR
unset ASDF_DIR unset ASDF_DIR
} }
setup_repo() {
cp -r $BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo $ASDF_DIR/repository
touch "$(asdf_dir)/tmp/repo-updated"
}