Skip to content

Commit

Permalink
fix: help for extension commands for plugins with hyphens in the name. (
Browse files Browse the repository at this point in the history
#1048)

* test: add test for plugin command list in asdf help
* fix: help for plugins containing hyphens
  • Loading branch information
yacchi committed Sep 23, 2021
1 parent 7e1f2a0 commit 3e0cb9a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/commands/command-help.bash
Expand Up @@ -14,18 +14,23 @@ EOF
}

asdf_extension_cmds() {
local plugins_path ext_cmds plugin
local plugins_path ext_cmd_path ext_cmds plugin
plugins_path="$(get_plugin_path)"
# use find instead of ls -1
# shellcheck disable=SC2012
ext_cmds="$(ls -1 "$plugins_path"/*/lib/commands/command*.bash 2>/dev/null |
sed "s#^$plugins_path/##;s#lib/commands/command##;s/.bash//;s/^-//;s/-/ /g")"
if test -n "$ext_cmds"; then
cut -d'/' -f 1 <<<"$ext_cmds" | uniq | while read -r plugin; do
for plugin in $(ls -1 "$plugins_path" 2>/dev/null | sed "s#^$plugins_path/##"); do
ext_cmd_path="$plugins_path/$plugin/lib/commands"
ext_cmds=$(
ls -1 "$ext_cmd_path"/command*.bash 2>/dev/null |
sed "s#$ext_cmd_path/##"
)
if [[ -n $ext_cmds ]]; then
printf "\\nPLUGIN %s\\n" "$plugin"
grep "$plugin/" <<<"$ext_cmds" | sed "s#^$plugin/# asdf $plugin#" | sort
done
fi
for ext_cmd in $ext_cmds; do
sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd"
done | sort
fi
done
}

help_command() {
Expand Down
22 changes: 22 additions & 0 deletions test/plugin_extension_command.bats
Expand Up @@ -28,6 +28,28 @@ teardown() {
echo "$output" | grep "asdf dummy foo bar" # should present commands without hipens
}

@test "asdf help shows extension commands for plugin with hyphens in the name" {
cd $PROJECT_DIR

plugin_name=dummy-hyphenated
install_mock_plugin $plugin_name

plugin_path="$(get_plugin_path $plugin_name)"
mkdir -p "$plugin_path/lib/commands"
touch "$plugin_path/lib/commands/command.bash"
touch "$plugin_path/lib/commands/command-foo.bash"
touch "$plugin_path/lib/commands/command-foo-bar.bash"

run asdf help
[ "$status" -eq 0 ]
[[ "$output" == *"PLUGIN $plugin_name"* ]]
# shellcheck disable=SC2154
listed_cmds=$(grep -c "asdf $plugin_name" <<<"${output}")
[[ $listed_cmds -eq 3 ]]
[[ "$output" == *"asdf $plugin_name foo"* ]]
[[ "$output" == *"asdf $plugin_name foo bar"* ]]
}

@test "asdf can execute plugin bin commands" {
plugin_path="$(get_plugin_path dummy)"

Expand Down

0 comments on commit 3e0cb9a

Please sign in to comment.