Skip to content

Commit 5ec6857

Browse files
authored
feat(config): enable legacy version file by default (#532)
Add strategy configuration support for legacy version file parsing with three options: latest_installed, latest_available, and specified. Update documentation to reflect these changes and default enable state.
1 parent 6802954 commit 5ec6857

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

docs/guides/configuration.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,35 @@ If you use `vfox` for the first time, an empty `config.yaml` file will be create
1212
Plugins **with support** can read the versions files used by other version managers,
1313
for example, `.nvmrc` in the case of Nodejs's `nvm`.
1414

15-
This capability is **turned off by default**, you can enable it as follows.
15+
This capability is **turned on by default**. The related configuration options are as follows:
1616

1717
```yaml
1818
legacyVersionFile:
1919
enable: true
20+
strategy: "specified" # Parsing strategy
2021
```
2122
23+
- `enable`: Whether to enable legacy version file parsing functionality
24+
- `strategy`: Parsing strategy, see strategy options below for details
25+
26+
### Strategy Options
27+
28+
`vfox` supports the following three parsing strategies:
29+
30+
- `latest_installed`: Use the latest installed version
31+
- `latest_available`: Use the latest available version
32+
- `specified`: Use the version specified in the legacy file (default)
33+
2234
::: warning
2335

2436
1. If both `.tool-versions` and other version manager's configuration files (`.nvmrc`, `.sdkmanrc`, etc.) exist in the
2537
directory, `vfox` **priority read** the `.tool-versions` file.
2638
2. Enabling this feature may cause `vfox` to refresh environment variables slightly slower, **please enable it according
2739
to your needs**.
28-
:::
40+
41+
:::
42+
43+
If you want to disable this feature, you can use the command: `vfox config legacyVersionFile.enable false`
2944

3045
## Proxy Settings
3146

@@ -77,16 +92,16 @@ registry:
7792
cache time is `12h`.
7893

7994
::: warning Special Value
95+
8096
- `-1`: Never expire
8197
- `0`: Do not cache
82-
:::
98+
:::
8399

84100
```yaml
85101
cache:
86102
availableHookDuration: 12h # s second, m minute, h hour
87103
```
88104

89-
90105
::: tip Cache File Path
91106
`$HOME/.version-fox/plugins/<plugin-name>/available.cache`
92107
:::

docs/plugins/create/howto.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ This hook is used to parse other configuration files to determine the version of
233233
This hook must be used with the `legacyFilenames` configuration item to tell `vfox` which files your plugin can parse.
234234
:::
235235

236+
::: tip Strategy Configuration
237+
When implementing this hook function, you can access the user-configured parsing strategy through `ctx.strategy`. For detailed strategy configuration, please refer to the [Configuration Documentation](../../guides/configuration.md#legacy-version-file).
238+
:::
239+
236240
**location**: `metadata.lua`
237241

238242
```lua
@@ -249,6 +253,8 @@ PLUGIN.legacyFilenames = {
249253
function PLUGIN:ParseLegacyFile(ctx)
250254
local filename = ctx.filename
251255
local filepath = ctx.filepath
256+
--- Parsing strategy (latest_installed, latest_available, specified)
257+
local strategy = ctx.strategy
252258
--- Get the list of versions of the current plugin installed
253259
local versions = ctx:getInstalledVersions()
254260

docs/zh-hans/guides/configuration.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,34 @@
1010

1111
插件 **支持** 读取其他版本管理器的配置文件, 例如: Nodejs 的`nvm``.nvmrc`文件, Java 的`SDKMAN``.sdkmanrc`文件等。
1212

13-
此能力**默认是关闭的**, 如果你想开启, 请按照以下方式配置:
13+
此能力**默认是开启的**。相关配置选项如下:
1414

1515
```yaml
1616
legacyVersionFile:
1717
enable: true
18+
strategy: "specified" # 解析策略
1819
```
1920
21+
- `enable`: 是否启用 legacy version file 解析功能
22+
- `strategy`: 解析策略,详见下方策略选项说明
23+
24+
### 策略选项
25+
26+
`vfox` 支持以下三种解析策略:
27+
28+
- `latest_installed`: 使用最新安装的版本
29+
- `latest_available`: 使用最新可用的版本
30+
- `specified`: 使用 legacy file 中指定的版本(默认)
31+
2032
::: warning
2133

2234
1. 如果目录里同时存在`.tool-versions`和其他版本管理器的配置文件(`.nvmrc`, `.sdkmanrc`等),
2335
`vfox` **优先加载**`.tool-versions`文件.
2436
2. 开启此功能可能会导致`vfox`刷新环境变量时略微变慢, **请根据自己的需求开启**。
25-
:::
37+
38+
:::
39+
40+
如果你想禁用此功能,可以使用命令:`vfox config legacyVersionFile.enable false`
2641

2742
## 代理设置
2843

@@ -74,20 +89,20 @@ registry:
7489
`vfox` 默认会缓存`search`命令的结果, 以减少网络请求次数。默认缓存时间为`12h`。
7590

7691
::: warning 特殊值
92+
7793
- `-1`: 永不过期
7894
- `0`: 不进行缓存
79-
:::
95+
:::
96+
8097
```yaml
8198
cache:
8299
availableHookDuration: 12h # s 秒, m 分钟, h 小时
83100
```
84101

85-
86102
::: tip 缓存文件路径
87103
`$HOME/.version-fox/plugins/<plugin-name>/available.cache`
88104
:::
89105

90-
91106
## Config 命令 <Badge type="tip" text=">= 0.4.0" vertical="middle" />
92107

93108
设置,查看配置

docs/zh-hans/plugins/create/howto.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ end
224224
该钩子函数必须配合 `legacyFilenames` 配置项使用, 告诉`vfox` 你的插件支持解析哪些文件。
225225
:::
226226

227+
::: tip 策略配置
228+
在实现此钩子函数时,你可以通过 `ctx.strategy` 获取用户配置的解析策略。详细的策略配置请参考[配置文档](../../guides/configuration.md#兼容版本文件)
229+
:::
230+
227231
**位置**: `metadata.lua`
228232

229233
```lua
@@ -242,6 +246,8 @@ function PLUGIN:ParseLegacyFile(ctx)
242246
local filename = ctx.filename
243247
--- 文件路径
244248
local filepath = ctx.filepath
249+
--- 解析策略 (latest_installed, latest_available, specified)
250+
local strategy = ctx.strategy
245251
--- 获取当前插件已安装的版本列表
246252
local versions = ctx:getInstalledVersions()
247253

internal/config/config_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package config_test
1818

1919
import (
20-
"github.com/version-fox/vfox/internal/config"
2120
"os"
2221
"testing"
22+
23+
"github.com/version-fox/vfox/internal/config"
2324
)
2425

2526
func TestNewConfig(t *testing.T) {
@@ -58,8 +59,8 @@ func TestConfigWithEmpty(t *testing.T) {
5859
if c.Storage.SdkPath != "" {
5960
t.Fatal("proxy url must be empty")
6061
}
61-
if c.LegacyVersionFile.Enable != false {
62-
t.Fatal("legacy version file enable must be false")
62+
if c.LegacyVersionFile.Enable != true {
63+
t.Fatal("legacy version file enable must be true")
6364
}
6465
if c.Registry.Address != "" {
6566
t.Fatal("registry address must be empty")

internal/config/legacy_version_file.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const (
2424
)
2525

2626
// LegacyVersionFile represents whether to enable the ability to parse legacy version files,
27-
// Disable by default.
2827
type LegacyVersionFile struct {
2928
Enable bool `yaml:"enable"`
3029
// Support three strategies:
@@ -36,6 +35,6 @@ type LegacyVersionFile struct {
3635
}
3736

3837
var EmptyLegacyVersionFile = &LegacyVersionFile{
39-
Enable: false,
38+
Enable: true,
4039
Strategy: DefaultStrategy,
4140
}

0 commit comments

Comments
 (0)