Optimise listing all plugins

When checking if a plugin is installed (to display a flag) it is not
necessary to loop through all installed plugins, since we already have
a name we can check directly.

Also expand test case to test this code path too.
This commit is contained in:
mig4 2018-10-27 20:05:02 +01:00
parent 4b857d0b7b
commit f994b07a2c
No known key found for this signature in database
GPG Key ID: 6CD3E1B61579CB43
3 changed files with 4 additions and 4 deletions

View File

@ -13,10 +13,7 @@ plugin_list_all_command() {
source_url=$(get_plugin_source_url "$index_plugin_name") source_url=$(get_plugin_source_url "$index_plugin_name")
installed_flag="" installed_flag=""
for local_plugin in "$plugins_local_path"/*; do [[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*'
local_plugin_name=$(basename "$local_plugin")
[[ "$index_plugin_name" == "$local_plugin_name" ]] && installed_flag="*"
done
printf "%-15s %-1s%s\\n" "$index_plugin_name" "$installed_flag" "$source_url" printf "%-15s %-1s%s\\n" "$index_plugin_name" "$installed_flag" "$source_url"
done done

View File

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

View File

@ -7,6 +7,7 @@ load test_helpers
setup() { setup() {
setup_asdf_dir setup_asdf_dir
setup_repo setup_repo
install_dummy_plugin
} }
teardown() { teardown() {
@ -16,6 +17,7 @@ teardown() {
@test "plugin_list_all list all plugins in the repository" { @test "plugin_list_all list all plugins in the repository" {
run plugin_list_all_command run plugin_list_all_command
local expected="bar http://example.com/bar local expected="bar http://example.com/bar
dummy *http://example.com/dummy
foo http://example.com/foo" foo http://example.com/foo"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "$expected" ] [ "$output" = "$expected" ]