Skip to content

fix: rename tool version filename environment variable for clarity #2101

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

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/ja-jp/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ pre_foo_bar = echo Executing with args: $@
- 未設定の場合: `$HOME/.asdfrc`の値が使用されます。
- 使用方法: `export ASDF_CONFIG_FILE=/home/john_doe/.config/asdf/.asdfrc`

### `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`
### `ASDF_TOOL_VERSIONS_FILENAME`

ツール名とバージョンの情報を格納するファイルのファイル名です。有効なファイル名であれば何でも設定できます。通常、`.tool-versions`ファイルを無視したい場合を除き、この値を変更するべきではありません。

- 未設定の場合: `.tool-versions`の値が使用されます。
- 使用方法: `export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=tool_versions`
- 使用方法: `export ASDF_TOOL_VERSIONS_FILENAME=tool_versions`

### `ASDF_DIR`

Expand Down Expand Up @@ -220,7 +220,7 @@ pre_foo_bar = echo Executing with args: $@
| 構成 | 値 | 値がセットされる過程 |
| :------------------------------------ | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------ |
| config file location | `$HOME/.asdfrc` | `ASDF_CONFIG_FILE`は空なので、`$HOME/.asdfrc`が使用されます。 |
| default tool versions filename | `.tool-versions` | `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`は空なので、`.tool-versions`が使用されます。 |
| default tool versions filename | `.tool-versions` | `ASDF_TOOL_VERSIONS_FILENAME`は空なので、`.tool-versions`が使用されます。 |
| asdf dir | `$HOME/.asdf` | `ASDF_DIR`は空なので、`bin/asdf`の親ディレクトリが使用されます。 |
| asdf data dir | `$HOME/.asdf` | `ASDF_DATA_DIR`は空であり、`$HOME`が存在するので、`$HOME/.asdf`が使用されます。 |
| concurrency | `auto` | `ASDF_CONCURRENCY`は空なので、[デフォルト構成](https://github.com/asdf-vm/asdf/blob/master/defaults)の`concurrency`の値に依存します。 |
Expand Down
6 changes: 3 additions & 3 deletions docs/ko-kr/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ pre_foo_bar = echo Executing with args: $@
- 미설정 시: `$HOME/.asdfrc`가 사용됩니다.
- 사용법: `export ASDF_CONFIG_FILE=/home/john_doe/.config/asdf/.asdfrc`

### `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`
### `ASDF_TOOL_VERSIONS_FILENAME`

툴 이름과 버전을 저장하는 파일의 파일이름입니다. 임의의 유효한 파일 이름이면 됩니다. 일반적으로, `.tool-version` 파일들을 무시하고 싶을 때 해당 값을 설정하세요.

- 미설정 시: `.tool-versions`가 사용됩니다.
- 사용법: `export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=tool_versions`
- 사용법: `export ASDF_TOOL_VERSIONS_FILENAME=tool_versions`

### `ASDF_DIR`

Expand Down Expand Up @@ -226,7 +226,7 @@ pre_foo_bar = echo Executing with args: $@
| 항목 | 값 | 값이 세팅되는 과정 |
| :------------------------------------ | :--------------- | :--------------------------------------------------------------------------------------------------------------------------- |
| config file location | `$HOME/.asdfrc` | `ASDF_CONFIG_FILE`가 비었으므로, `$HOME/.asdfrc`을 사용 |
| default tool versions filename | `.tool-versions` | `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`가 비었으므로, `.tool-versions`을 사용 |
| default tool versions filename | `.tool-versions` | `ASDF_TOOL_VERSIONS_FILENAME`가 비었으므로, `.tool-versions`을 사용 |
| asdf dir | `$HOME/.asdf` | `ASDF_DIR`가 비었으므로, `bin/asdf`의 한 단계 상위 디렉토리 사용 |
| asdf data dir | `$HOME/.asdf` | `ASDF_DATA_DIR`가 비었으므로, `$HOME/.asdf`를 `$HOME`으로 사용. |
| concurrency | `auto` | `ASDF_CONCURRENCY`가 비었으므로, [기본 설정](https://github.com/asdf-vm/asdf/blob/master/defaults)의 `concurrency` 값에 의존 |
Expand Down
6 changes: 3 additions & 3 deletions docs/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ Path to the `.asdfrc` configuration file. Can be set to any location. Must be an
- If Unset: `$HOME/.asdfrc` will be used.
- Usage: `export ASDF_CONFIG_FILE=/home/john_doe/.config/asdf/.asdfrc`

### `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME`
### `ASDF_TOOL_VERSIONS_FILENAME`

The filename of the file storing the tool names and versions. Can be any valid filename. Typically, you should not set this value unless you want to ignore `.tool-versions` files.

- If Unset: `.tool-versions` will be used.
- Usage: `export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=tool_versions`
- Usage: `export ASDF_TOOL_VERSIONS_FILENAME=tool_versions`

### `ASDF_DIR`

Expand Down Expand Up @@ -220,7 +220,7 @@ would result in the following outcomes:
| Configuration | Value | Calculated by |
| :------------------------------------ | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
| config file location | `$HOME/.asdfrc` | `ASDF_CONFIG_FILE` is empty, so use `$HOME/.asdfrc` |
| default tool versions filename | `.tool-versions` | `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME` is empty, so use `.tool-versions` |
| default tool versions filename | `.tool-versions` | `ASDF_TOOL_VERSIONS_FILENAME` is empty, so use `.tool-versions` |
| asdf dir | `$HOME/.asdf` | `ASDF_DIR` is empty, so use parent dir of `bin/asdf` |
| asdf data dir | `$HOME/.asdf` | `ASDF_DATA_DIR` is empty so use `$HOME/.asdf` as `$HOME` exists. |
| concurrency | `auto` | `ASDF_CONCURRENCY` is empty, so rely on `concurrency` value from the [default configuration](https://github.com/asdf-vm/asdf/blob/master/defaults) |
Expand Down
2 changes: 1 addition & 1 deletion docs/pt-br/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ legacy_version_file = yes
## Variáveis de ambiente

- `ASDF_CONFIG_FILE` - O padrão é `~ /.asdfrc` conforme descrito acima. Pode ser definido para qualquer local.
- `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME` - O nome do arquivo que armazena os nomes e versões das ferramentas. O padrão é `.tool-versions`. Pode ser qualquer nome de arquivo válido. Normalmente você não deve substituir o valor padrão, a menos que deseja que o asdf ignore os arquivos `.tool-versions`.
- `ASDF_TOOL_VERSIONS_FILENAME` - O nome do arquivo que armazena os nomes e versões das ferramentas. O padrão é `.tool-versions`. Pode ser qualquer nome de arquivo válido. Normalmente você não deve substituir o valor padrão, a menos que deseja que o asdf ignore os arquivos `.tool-versions`.
- `ASDF_DIR` - O padrão é `~/.asdf` - Localização dos arquivos `asdf`. Se você instalar `asdf` em algum outro diretório, defina-o para esse diretório. Por exemplo, se você estiver instalando através do AUR, você deve definir isso para `/opt/asdf-vm`.
- `ASDF_DATA_DIR` - O padrão é `~/.asdf` - Local onde `asdf` instala plugins, correções e instalações. Pode ser definido para qualquer local antes de fornecer `asdf.sh` ou `asdf.fish` mencionado na seção acima. Para Elvish, isso pode ser definido acima de `use asdf`.
2 changes: 1 addition & 1 deletion docs/zh-hans/manage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ concurrency = auto
## 环境变量

- `ASDF_CONFIG_FILE` - 如上所述默认为 `~/.asdfrc` 文件。可以被设置在任何位置。
- `ASDF_DEFAULT_TOOL_VERSIONS_FILENAME` - 存储工具名称和版本的文件名。默认为 `.tool-versions`。可以是任何有效的文件名。通常,除非你知道你希望 asdf 忽略 `.tool-versions` 文件,否则不应该覆盖默认值。
- `ASDF_TOOL_VERSIONS_FILENAME` - 存储工具名称和版本的文件名。默认为 `.tool-versions`。可以是任何有效的文件名。通常,除非你知道你希望 asdf 忽略 `.tool-versions` 文件,否则不应该覆盖默认值。
- `ASDF_DIR` - 默认为 `~/.asdf` - `asdf` 脚本的位置。如果你把 `asdf` 安装到了其他目录,请设置该变量到那个目录。比如,如果通过 AUR 进行安装,则应设置该变量为 `/opt/asdf-vm`。
- `ASDF_DATA_DIR` - 默认为 `~/.asdf` - `asdf` 安装插件、垫片和安装器的位置。可以被设置在上一节提到的生效 `asdf.sh` 或者 `asdf.fish` 之间的任何位置。对于 Elvish,这可以设置在 `use asdf` 上面。
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/mgechev/revive v1.7.0
github.com/otiai10/copy v1.14.0
github.com/rogpeppe/go-internal v1.12.0
github.com/sethvargo/go-envconfig v1.1.1
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.27.5
golang.org/x/sys v0.31.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sethvargo/go-envconfig v1.1.1 h1:JDu8Q9baIzJf47NPkzhIB6aLYL0vQ+pPypoYrejS9QY=
github.com/sethvargo/go-envconfig v1.1.1/go.mod h1:JLd0KFWQYzyENqnEPWWZ49i4vzZo/6nRidxI8YvGiHw=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY=
github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M=
Expand Down
39 changes: 25 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
package config

import (
"context"
"io/fs"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/sethvargo/go-envconfig"
"gopkg.in/ini.v1"
)

Expand All @@ -35,14 +33,11 @@ var pluginRepoCheckDurationDefault = PluginRepoCheckDuration{Every: 60}
// Config is the primary value this package builds and returns
type Config struct {
Home string
ConfigFile string `env:"ASDF_CONFIG_FILE, overwrite"`
DefaultToolVersionsFilename string `env:"ASDF_DEFAULT_TOOL_VERSIONS_FILENAME, overwrite"`
// Unclear if this value will be needed with the golang implementation.
// AsdfDir string
DataDir string `env:"ASDF_DATA_DIR, overwrite"`
// Field that stores the settings struct if it is loaded
Settings Settings
PluginIndexURL string
ConfigFile string
DefaultToolVersionsFilename string
DataDir string
Settings Settings
PluginIndexURL string
}

// Settings is a struct that stores config values from the asdfrc file
Expand Down Expand Up @@ -102,10 +97,26 @@ func LoadConfig() (Config, error) {
return Config{}, err
}

ctx := context.Background()
err = envconfig.Process(ctx, config)
if err != nil {
return Config{}, err
configFile := os.Getenv("ASDF_CONFIG_FILE")
if configFile != "" {
config.ConfigFile = configFile
}

dataDir := os.Getenv("ASDF_DATA_DIR")
if dataDir != "" {
config.DataDir = dataDir
}

versionFilename := os.Getenv("ASDF_TOOL_VERSIONS_FILENAME")
if versionFilename != "" {
config.DefaultToolVersionsFilename = versionFilename
} else {
// ASDF_TOOL_VERSIONS_FILENAME is the new environment variable name. It used
// to be named ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
versionFilename = os.Getenv("ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")
if versionFilename != "" {
config.DefaultToolVersionsFilename = versionFilename
}
}

config.Home = homeDir
Expand Down
2 changes: 1 addition & 1 deletion internal/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Write(conf config.Config, version string, writer io.Writer) error {
fmt.Fprintf(writer, "%s\n", version)

fmt.Fprintln(writer, "\nASDF INTERNAL VARIABLES:")
fmt.Fprintf(writer, "ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=%s\n", conf.DefaultToolVersionsFilename)
fmt.Fprintf(writer, "ASDF_TOOL_VERSIONS_FILENAME=%s\n", conf.DefaultToolVersionsFilename)
fmt.Fprintf(writer, "ASDF_DATA_DIR=%s\n", conf.DataDir)
fmt.Fprintf(writer, "ASDF_CONFIG_FILE=%s\n", conf.ConfigFile)

Expand Down
14 changes: 7 additions & 7 deletions test/utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,18 @@ teardown() {
[ "$output" = "" ]
}

@test "find_versions should return \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
echo "dummy 0.1.0" >"$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
@test "find_versions should return \$ASDF_TOOL_VERSIONS_FILENAME if set" {
ASDF_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
echo "dummy 0.1.0" >"$ASDF_TOOL_VERSIONS_FILENAME"

run find_versions "dummy" "$PROJECT_DIR"
[ "$status" -eq 0 ]
[ "$output" = "0.1.0|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]
[ "$output" = "0.1.0|$ASDF_TOOL_VERSIONS_FILENAME" ]
}

@test "find_versions should check \$HOME legacy files before \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
echo "dummy 0.2.0" >"$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
@test "find_versions should check \$HOME legacy files before \$ASDF_TOOL_VERSIONS_FILENAME" {
ASDF_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
echo "dummy 0.2.0" >"$ASDF_TOOL_VERSIONS_FILENAME"
echo "dummy 0.1.0" >"$HOME/.dummy-version"
echo "legacy_version_file = yes" >"$HOME/.asdfrc"

Expand Down
36 changes: 18 additions & 18 deletions test/version_commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -282,42 +282,42 @@ teardown() {
[ "$(cat "$HOME/.tool-versions")" = "dummy path:$PROJECT_DIR/local" ]
}

@test "local should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="local-tool-versions"
@test "local should write to ASDF_TOOL_VERSIONS_FILENAME" {
export ASDF_TOOL_VERSIONS_FILENAME="local-tool-versions"
run asdf local "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ "$(cat "$ASDF_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ -z "$(cat .tool-versions)" ]
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
unset ASDF_TOOL_VERSIONS_FILENAME
}

@test "local should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="local-tool-versions"
echo 'dummy 1.0.0' >>"$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
@test "local should overwrite contents of ASDF_TOOL_VERSIONS_FILENAME if set" {
export ASDF_TOOL_VERSIONS_FILENAME="local-tool-versions"
echo 'dummy 1.0.0' >>"$ASDF_TOOL_VERSIONS_FILENAME"
run asdf local "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ "$(cat "$ASDF_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ -z "$(cat .tool-versions)" ]
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
unset ASDF_TOOL_VERSIONS_FILENAME
}

@test "global should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" {
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="global-tool-versions"
@test "global should write to ASDF_TOOL_VERSIONS_FILENAME" {
export ASDF_TOOL_VERSIONS_FILENAME="global-tool-versions"
run asdf global "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat "$HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ "$(cat "$HOME/$ASDF_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ -z "$(cat "$HOME/.tool-versions")" ]
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
unset ASDF_TOOL_VERSIONS_FILENAME
}

@test "global should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="global-tool-versions"
echo 'dummy 1.0.0' >>"$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
@test "global should overwrite contents of ASDF_TOOL_VERSIONS_FILENAME if set" {
export ASDF_TOOL_VERSIONS_FILENAME="global-tool-versions"
echo 'dummy 1.0.0' >>"$ASDF_TOOL_VERSIONS_FILENAME"
run asdf global "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat "$HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ "$(cat "$HOME/$ASDF_TOOL_VERSIONS_FILENAME")" = "dummy 1.1.0" ]
[ -z "$(cat "$HOME/.tool-versions")" ]
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
unset ASDF_TOOL_VERSIONS_FILENAME
}

@test "local should preserve symlinks when setting versions" {
Expand Down