From 1ee0c62e51791ee793deb28af0491ba27e6d269f Mon Sep 17 00:00:00 2001 From: Jonathan Beverly Date: Tue, 10 May 2022 22:36:28 +0000 Subject: [PATCH] Support for disabling short-name repo --- defaults | 1 + lib/utils.bash | 10 +++++----- test/plugin_add_command.bats | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/defaults b/defaults index 0b0964f5..b04042b9 100644 --- a/defaults +++ b/defaults @@ -1,2 +1,3 @@ # enables the use of .ruby-version like files used by other version managers legacy_version_file = no +asdf_repository_url = https://github.com/asdf-vm/asdf-plugins.git \ No newline at end of file diff --git a/lib/utils.bash b/lib/utils.bash index 84f2a2c4..8b860cba 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -32,10 +32,6 @@ asdf_dir() { printf "%s\\n" "$ASDF_DIR" } -asdf_repository_url() { - printf "https://github.com/asdf-vm/asdf-plugins.git\\n" -} - asdf_data_dir() { local data_dir @@ -404,7 +400,11 @@ initialize_or_update_repository() { local repository_url local repository_path - repository_url=$(asdf_repository_url) + repository_url="$(get_asdf_config_value "asdf_repository_url")" + if [ ! -n "$repository_url" ]; then + printf "No short-name plugin repository in configuration\\n" >&2 + exit 1 + fi repository_path=$(asdf_data_dir)/repository if [ ! -d "$repository_path" ]; then diff --git a/test/plugin_add_command.bats b/test/plugin_add_command.bats index 021e3850..94b39780 100644 --- a/test/plugin_add_command.bats +++ b/test/plugin_add_command.bats @@ -41,6 +41,31 @@ teardown() { [ "$output" = "elixir" ] } +@test "plugin_add command with no URL specified adds a plugin using repo from config" { + ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc + cat > $ASDF_CONFIG_FILE <<-EOM +asdf_repository_url = "https://github.com/asdf-vm/asdf-plugins.git" +EOM + + run asdf plugin add "elixir" + [ "$status" -eq 0 ] + + run asdf plugin-list + # whitespace between 'elixir' and url is from printf %-15s %s format + [ "$output" = "elixir" ] +} + +@test "plugin_add command with no URL specified fails to add a plugin when no default repo" { + ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc + cat > $ASDF_CONFIG_FILE <<-EOM +# no asdf_repository_url for the tests +EOM + + run asdf plugin add "elixir" + [ "$status" -eq 1 ] + [ "$output" = "No short-name plugin repository configured" ] +} + @test "plugin_add command with URL specified adds a plugin using repo" { install_mock_plugin_repo "dummy"