feat: update config opt name & rewrite docs

This commit is contained in:
jthegedus 2022-06-28 02:47:27 +10:00
parent 4a54c4529d
commit 286043bd86
5 changed files with 68 additions and 48 deletions

View File

@ -7,7 +7,9 @@ Configuration of `asdf` encompasses both the sharable `.tool-versions` files as
Whenever `.tool-versions` file is present in a directory, the tool versions it declares will be used in that directory and any subdirectories. Whenever `.tool-versions` file is present in a directory, the tool versions it declares will be used in that directory and any subdirectories.
::: warning Note ::: warning Note
Global defaults can be set in the file `$HOME/.tool-versions` Global defaults can be set in the file `$HOME/.tool-versions`
::: :::
This is what a `.tool-versions` file looks like: This is what a `.tool-versions` file looks like:
@ -57,7 +59,7 @@ legacy_version_file = no
use_release_candidates = no use_release_candidates = no
always_keep_download = no always_keep_download = no
plugin_repository_last_check_duration = 60 plugin_repository_last_check_duration = 60
disable_short_name_repository = yes disable_plugin_short_name_repository = no
``` ```
### `legacy_version_file` ### `legacy_version_file`
@ -89,7 +91,7 @@ Configure the `asdf install` command to keep or delete the source code or binary
### `plugin_repository_last_check_duration` ### `plugin_repository_last_check_duration`
Configure the duration since the last asdf plugin repository sync to the next. Commands `asdf plugin add <name>` or `asdf plugin list all` will trigger a check of the duration, if the duration has passed then a sync occurs. Configure the duration since the last asdf plugin repository sync to the next. Sync events will trigger a check of the duration, if the duration has passed then a sync occurs.
| Options | Description | | Options | Description |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- | | :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- |
@ -97,19 +99,35 @@ Configure the duration since the last asdf plugin repository sync to the next. C
| `0` | Sync on each trigger event | | `0` | Sync on each trigger event |
| `never` | Never sync | | `never` | Never sync |
### `disable_short_name_repository` Sync events occur when the following commands are executed:
- `asdf plugin add <name>`
- `asdf plugin list all`
`asdf plugin add <name> <git-url>` does NOT trigger a plugin sync.
### `disable_plugin_short_name_repository`
Disable synchronization of the asdf plugin short-name repository. Sync events will exit early if the short-name repository is disabled.
| Options | Description |
| :--------------------------------------------------------- | :-------------------------------------------------------- |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Clone or update the asdf plugin repository on sync events |
| `yes` | Disable short-name plugin repository |
Sync events occur when the following commands are executed:
- `asdf plugin add <name>`
- `asdf plugin list all`
`asdf plugin add <name> <git-url>` does NOT trigger a plugin sync.
::: warning Note ::: warning Note
Existing plugins available from the short-name repository will continue to be installable.
Disabling the plugin short-name repository does not remove plugins previously installed from this source. Plugins can be removed with `asdf plugin remove <name>`. Removing a plugin will remove all installed versions of the managed tool.
::: :::
Disable installing or updating the short-name repository. Commands `asdf plugin add <name>` or `asdf plugin list all` will fail if no short-name repository has been configured.
| Options | Description |
| :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------- |
| Git URL of a short-name repository | Clone this repository if installing plugins without URL |
| `` | Disable short-name plugin repository. |
## Environment Variables ## Environment Variables
- `ASDF_CONFIG_FILE` - Defaults to `~/.asdfrc` as described above. Can be set to any location. - `ASDF_CONFIG_FILE` - Defaults to `~/.asdfrc` as described above. Can be set to any location.

View File

@ -75,7 +75,7 @@ Removing a plugin will remove all installations of the tool made with the plugin
## Syncing the Short-name Repository ## Syncing the Short-name Repository
::: tip Recommendation ::: tip Recommendation
The short-name repo can be disabled using the flag `disable_short_name_repository`. The short-name repo can be disabled using the flag `disable_plugin_short_name_repository`.
::: :::
The short-name repo is synced to your local machine and periodically refreshed. This period is determined by the following method: The short-name repo is synced to your local machine and periodically refreshed. This period is determined by the following method:

View File

@ -404,8 +404,8 @@ initialize_or_update_repository() {
local repository_url local repository_url
local repository_path local repository_path
disable_short_name_repo="$(get_asdf_config_value "disable_short_name_repository")" disable_plugin_short_name_repo="$(get_asdf_config_value "disable_plugin_short_name_repository")"
if [ "yes" == "$disable_short_name_repo" ]; then if [ "yes" == "$disable_plugin_short_name_repo" ]; then
printf "Short-name plugin repository is disabled\\n" >&2 printf "Short-name plugin repository is disabled\\n" >&2
exit 1 exit 1
fi fi

View File

@ -16,7 +16,7 @@ teardown() {
run asdf plugin add "plugin_with-all-valid-CHARS-123" "${BASE_DIR}/repo-plugin_with-all-valid-CHARS-123" run asdf plugin add "plugin_with-all-valid-CHARS-123" "${BASE_DIR}/repo-plugin_with-all-valid-CHARS-123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run asdf plugin-list run asdf plugin list
[ "$output" = "plugin_with-all-valid-CHARS-123" ] [ "$output" = "plugin_with-all-valid-CHARS-123" ]
} }
@ -36,41 +36,30 @@ teardown() {
run asdf plugin add "elixir" run asdf plugin add "elixir"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run asdf plugin-list run asdf plugin list
# whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "elixir" ] [ "$output" = "elixir" ]
} }
@test "plugin_add command with no URL specified adds a plugin when short name repository is enabled" { @test "plugin_add command with no URL specified adds a plugin when short name repository is enabled" {
export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo "" > $ASDF_CONFIG_DEFAULT_FILE echo "disable_plugin_short_name_repository=no" >$ASDF_CONFIG_DEFAULT_FILE
export ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc
cat > $ASDF_CONFIG_FILE <<-EOM
disable_short_name_repository=no
EOM
run asdf plugin add "elixir" run asdf plugin add "elixir"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run asdf plugin-list local expected="elixir"
# whitespace between 'elixir' and url is from printf %-15s %s format run asdf plugin list
[ "$output" = "elixir" ] [ "$output" = "$expected" ]
} }
@test "plugin_add command with no URL specified fails to add a plugin when disabled" { @test "plugin_add command with no URL specified fails to add a plugin when disabled" {
export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo "" > $ASDF_CONFIG_DEFAULT_FILE echo "disable_plugin_short_name_repository=yes" >$ASDF_CONFIG_DEFAULT_FILE
local expected="Short-name plugin repository is disabled"
export ASDF_CONFIG_FILE=$BATS_TMPDIR/asdfrc
cat > $ASDF_CONFIG_FILE <<-EOM
disable_short_name_repository=yes
EOM
run asdf plugin add "elixir" run asdf plugin add "elixir"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[ "$output" = "Short-name plugin repository is disabled" ] [ "$output" = "$expected" ]
} }
@test "plugin_add command with URL specified adds a plugin using repo" { @test "plugin_add command with URL specified adds a plugin using repo" {
@ -79,7 +68,7 @@ EOM
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy" run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
run asdf plugin-list run asdf plugin list
# whitespace between 'elixir' and url is from printf %-15s %s format # whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "dummy" ] [ "$output" = "dummy" ]
} }
@ -109,7 +98,7 @@ EOM
@test "plugin_add command executes configured pre hook (generic)" { @test "plugin_add command executes configured pre hook (generic)" {
install_mock_plugin_repo "dummy" install_mock_plugin_repo "dummy"
cat > $HOME/.asdfrc <<-'EOM' cat >$HOME/.asdfrc <<-'EOM'
pre_asdf_plugin_add = echo ADD ${@} pre_asdf_plugin_add = echo ADD ${@}
EOM EOM
@ -123,7 +112,7 @@ plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
@test "plugin_add command executes configured pre hook (specific)" { @test "plugin_add command executes configured pre hook (specific)" {
install_mock_plugin_repo "dummy" install_mock_plugin_repo "dummy"
cat > $HOME/.asdfrc <<-'EOM' cat >$HOME/.asdfrc <<-'EOM'
pre_asdf_plugin_add_dummy = echo ADD pre_asdf_plugin_add_dummy = echo ADD
EOM EOM
@ -137,7 +126,7 @@ plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
@test "plugin_add command executes configured post hook (generic)" { @test "plugin_add command executes configured post hook (generic)" {
install_mock_plugin_repo "dummy" install_mock_plugin_repo "dummy"
cat > $HOME/.asdfrc <<-'EOM' cat >$HOME/.asdfrc <<-'EOM'
post_asdf_plugin_add = echo ADD ${@} post_asdf_plugin_add = echo ADD ${@}
EOM EOM
@ -151,7 +140,7 @@ ADD dummy"
@test "plugin_add command executes configured post hook (specific)" { @test "plugin_add command executes configured post hook (specific)" {
install_mock_plugin_repo "dummy" install_mock_plugin_repo "dummy"
cat > $HOME/.asdfrc <<-'EOM' cat >$HOME/.asdfrc <<-'EOM'
post_asdf_plugin_add_dummy = echo ADD post_asdf_plugin_add_dummy = echo ADD
EOM EOM

View File

@ -12,51 +12,64 @@ teardown() {
clean_asdf_dir clean_asdf_dir
} }
@test "plugin_list_all should exit before syncing the plugin repo if disabled" {
export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
echo 'disable_plugin_short_name_repository=yes' >$ASDF_CONFIG_DEFAULT_FILE
local expected="Short-name plugin repository is disabled"
run asdf plugin list all
[ "$status" -eq 1 ]
[ "$output" = "$expected" ]
}
@test "plugin_list_all should sync repo when check_duration set to 0" { @test "plugin_list_all should sync repo when check_duration set to 0" {
echo 'plugin_repository_last_check_duration = 0' > $HOME/.asdfrc export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
run asdf plugin-list-all echo 'plugin_repository_last_check_duration = 0' >$ASDF_CONFIG_DEFAULT_FILE
local expected_plugin_repo_sync="updating plugin repository..." local expected_plugin_repo_sync="updating plugin repository..."
local expected_plugins_list="\ local expected_plugins_list="\
bar http://example.com/bar bar http://example.com/bar
dummy *http://example.com/dummy dummy *http://example.com/dummy
foo http://example.com/foo" foo http://example.com/foo"
run asdf plugin list all
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" =~ "$expected_plugin_repo_sync" ]] [[ "$output" =~ "$expected_plugin_repo_sync" ]]
[[ "$output" =~ "$expected_plugins_list" ]] [[ "$output" =~ "$expected_plugins_list" ]]
} }
@test "plugin_list_all no immediate repo sync expected because check_duration is greater than 0" { @test "plugin_list_all no immediate repo sync expected because check_duration is greater than 0" {
echo 'plugin_repository_last_check_duration = 10' > $HOME/.asdfrc export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
run asdf plugin-list-all echo 'plugin_repository_last_check_duration = 10' >$ASDF_CONFIG_DEFAULT_FILE
local expected="\ local expected="\
bar http://example.com/bar bar http://example.com/bar
dummy *http://example.com/dummy dummy *http://example.com/dummy
foo http://example.com/foo" foo http://example.com/foo"
run asdf plugin list all
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "$expected" ] [ "$output" = "$expected" ]
} }
@test "plugin_list_all skips repo sync because check_duration is set to never" { @test "plugin_list_all skips repo sync because check_duration is set to never" {
echo 'plugin_repository_last_check_duration = never' > $HOME/.asdfrc export ASDF_CONFIG_DEFAULT_FILE=$HOME/.asdfrc
run asdf plugin-list-all echo 'plugin_repository_last_check_duration = never' >$ASDF_CONFIG_DEFAULT_FILE
local expected="\ local expected="\
bar http://example.com/bar bar http://example.com/bar
dummy *http://example.com/dummy dummy *http://example.com/dummy
foo http://example.com/foo" foo http://example.com/foo"
run asdf plugin list all
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "$expected" ] [ "$output" = "$expected" ]
} }
@test "plugin_list_all list all plugins in the repository" { @test "plugin_list_all list all plugins in the repository" {
run asdf plugin-list-all
local expected="\ local expected="\
bar http://example.com/bar bar http://example.com/bar
dummy *http://example.com/dummy dummy *http://example.com/dummy
foo http://example.com/foo" foo http://example.com/foo"
run asdf plugin list all
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "$output" = "$expected" ] [ "$output" = "$expected" ]
} }