Skip to content

Commit

Permalink
Merge branch 'master' into add-unset-all
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardsanta authored Sep 6, 2023
2 parents 7bb968a + e83d71e commit 79906e7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion asdf.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ end
if not contains $_asdf_shims $fish_user_paths
set --global --prepend fish_user_paths $_asdf_shims
end
set --erase _asdf_bin _asdf_shims
set --erase _asdf_bin
set --erase _asdf_shims

# The asdf function is a wrapper so we can export variables
function asdf
Expand Down
1 change: 0 additions & 1 deletion docs/plugins/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ Determine the latest stable version of a tool. If absent, the asdf core will `ta
The script should accept a single argument, the filter query.

```bash
"${plugin_path}"/bin/latest-stable ""
"${plugin_path}"/bin/latest-stable "$query"
```

Expand Down
6 changes: 3 additions & 3 deletions lib/functions/plugins.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ plugin_list_command() {
) | awk '{ if (NF > 1) { printf("%-28s", $1) ; $1="" }; print $0}'
else
display_error 'No plugins installed'
exit 1
exit 0
fi
}

Expand Down Expand Up @@ -79,8 +79,8 @@ plugin_add_command() {
mkdir -p "$(asdf_data_dir)/plugins"

if [ -d "$plugin_path" ]; then
display_error "Plugin named $plugin_name already added"
exit 2
printf '%s\n' "Plugin named $plugin_name already added"
exit 0
else
asdf_run_hook "pre_asdf_plugin_add" "$plugin_name"
asdf_run_hook "pre_asdf_plugin_add_${plugin_name}"
Expand Down
11 changes: 9 additions & 2 deletions lib/functions/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ version_command() {
done

if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then
sed -i.bak -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$file"
rm -f "$file".bak
local temp_dir
temp_dir=${TMPDIR:-/tmp}

local temp_tool_versions_file
temp_tool_versions_file=$(mktemp "$temp_dir/asdf-tool-versions-file.XXXXXX")

cp -f "$file" "$temp_tool_versions_file"
sed -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$temp_tool_versions_file" >"$file"
rm -f "$temp_tool_versions_file"
else
# Add a trailing newline at the end of the file if missing
[[ -f "$file" && -n "$(tail -c1 "$file")" ]] && printf '\n' >>"$file"
Expand Down
4 changes: 2 additions & 2 deletions test/plugin_add_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ teardown() {
[ "$output" = "dummy" ]
}

@test "plugin_add command with URL specified run twice returns error second time" {
@test "plugin_add command with URL specified twice returns success on second time" {
install_mock_plugin_repo "dummy"

run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
[ "$status" -eq 2 ]
[ "$status" -eq 0 ]
[ "$output" = "Plugin named dummy already added" ]
}

Expand Down

0 comments on commit 79906e7

Please sign in to comment.