Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Auto-install missing versions in asdf local. #1714

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ always_keep_download = no
plugin_repository_last_check_duration = 60
disable_plugin_short_name_repository = no
concurrency = auto
local_command_auto_install_missing_version = no
```

### `legacy_version_file`
Expand Down Expand Up @@ -152,6 +153,17 @@ The default number of cores to use during compilation.

Note: the environment variable `ASDF_CONCURRENCY` take precedence if set.

### `local_command_auto_install_missing_version`

Configure the `asdf local` command with the ability to auto-install missing versions.

For example, if you want your `.tool-versions` file to reflect `ruby 2.7.8`, you can invoke `asdf local ruby 2.7.8`. By default, if Ruby 2.7.8 is not yet installed, this command will exit with an error. However, if you set `local_command_auto_install_missing_version = yes` in `~/.asdfrc`, Ruby 2.7.8 will be downloaded & installed if necessary, and then `.tool-versions` will be updated.

| Options | Description |
| :--------------------------------------------------------- | :--------------------------------------------------------- |
| `no` <Badge type="tip" text="default" vertical="middle" /> | Only update .tool-versions if version is already available |
| `yes` | Install version if missing, then update .tool-versions |

### Plugin Hooks

It is possible to execute custom code:
Expand Down
4 changes: 4 additions & 0 deletions lib/commands/command-local.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

# shellcheck source=lib/commands/version_commands.bash
. "$(dirname "$ASDF_CMD_FILE")/version_commands.bash"
# shellcheck source=lib/commands/reshim.bash
. "$(dirname "$ASDF_CMD_FILE")/reshim.bash"
# shellcheck source=lib/functions/installs.bash
. "$(dirname "$(dirname "$0")")/lib/functions/installs.bash"

local_command "$@"
9 changes: 7 additions & 2 deletions lib/functions/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ version_command() {
fi

if ! (check_if_version_exists "$plugin_name" "$version"); then
version_not_installed_text "$plugin_name" "$version" 1>&2
exit 1
auto_install=$(get_asdf_config_value "local_command_auto_install_missing_version")
if [[ "$auto_install" == "yes" ]]; then
install_tool_version "$plugin_name" "$version"
else
version_not_installed_text "$plugin_name" "$version" 1>&2
exit 1
fi
fi

resolved_versions+=("$version")
Expand Down