Skip to content

Commit 449bdc9

Browse files
committed
fix: use scope docs and legacy file parsing
1 parent f615b50 commit 449bdc9

7 files changed

Lines changed: 73 additions & 10 deletions

File tree

cmd/commands/use.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ var Use = &cli.Command{
4646
&cli.BoolFlag{
4747
Name: "project",
4848
Aliases: []string{"p"},
49-
Usage: "Used with the current directory (default)",
49+
Usage: "Used with the current directory",
5050
},
5151
&cli.BoolFlag{
5252
Name: "session",
5353
Aliases: []string{"s"},
54-
Usage: "Used with the current shell session",
54+
Usage: "Used with the current shell session (default)",
5555
},
5656
&cli.BoolFlag{
5757
Name: "unlink",
@@ -118,7 +118,7 @@ func determineScopeFromFlags(cmd *cli.Command) env.UseScope {
118118
if cmd.IsSet("project") {
119119
return env.Project
120120
}
121-
// Default to project if no scope specified
121+
// Default to session if no scope specified
122122
return env.Session
123123
}
124124

docs/guides/quick-start.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ Always use exact version numbers to ensure project stability and reproducibility
203203
**Project > Session > Global > System**
204204

205205
::: info 📌 Default Behavior
206-
**vfox defaults to Session level**, if you don't specify `-p` (project level) or `-g` (global) flags, using `vfox use` command is equivalent to `vfox use -s`. When you close the shell session, the Session level configuration is automatically cleaned up and destroyed.
206+
**On Unix-like systems, vfox defaults to Session level**. If you don't specify `-p` (project level) or `-g` (global) flags, using `vfox use` command is equivalent to `vfox use -s`. When you close the shell session, the Session level configuration is automatically cleaned up and destroyed.
207+
208+
**On Windows, vfox defaults to Global level** because shell hook support is not available in the same way, so `vfox use` without an explicit scope behaves like `vfox use -g`.
207209
:::
208210
209211
### Scope Overview
@@ -222,7 +224,7 @@ vfox creates directory symlinks in different scopes pointing to actual SDK insta
222224
223225
```bash
224226
# Project > Session > Global > System
225-
$PWD/.vfox/sdks/nodejs/bin:~/.vfox/tmp/<pid>/nodejs/bin:~/.vfox/sdks/nodejs/bin:/usr/bin:...
227+
$PWD/.vfox/sdks/nodejs/bin:~/.vfox/tmp/<pid>/sdks/nodejs/bin:~/.vfox/sdks/nodejs/bin:/usr/bin:...
226228
```
227229
228230
:::

docs/usage/core-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ vfox unuse [options] <sdk-name>
127127
:::
128128

129129
::: warning Effect
130-
After using `unuse`, the SDK will no longer be active in the specified scope. If the SDK is configured in other scopes, those will take precedence according to vfox's scope hierarchy (Session > Project > Global).
130+
After using `unuse`, the SDK will no longer be active in the specified scope. If the SDK is configured in other scopes, those will take precedence according to vfox's scope hierarchy (Project > Session > Global).
131131
:::
132132

133133
## Uninstall

docs/zh-hans/guides/quick-start.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ vfox use -g nodejs@latest
202202
**Project > Session > Global > System**
203203

204204
::: info 📌 默认行为
205-
**vfox 默认是 Session 级别**,如果不指定 `-p`(项目级)或 `-g`(全局)标志,直接使用 `vfox use` 命令等同于 `vfox use -s`。关闭 Shell 会话时,Session 级别的配置会自动清理销毁。
205+
**在 Unix-like 系统上,vfox 默认是 Session 级别**。如果不指定 `-p`(项目级)或 `-g`(全局)标志,直接使用 `vfox use` 命令等同于 `vfox use -s`。关闭 Shell 会话时,Session 级别的配置会自动清理销毁。
206+
207+
**在 Windows 上,vfox 默认是 Global 级别**,因为其 Shell hook 支持方式不同,所以未显式指定作用域时,`vfox use` 的行为等同于 `vfox use -g`
206208
:::
207209

208210
### 作用域概览
@@ -221,7 +223,7 @@ vfox 通过在不同作用域创建目录软链来指向实际 SDK 安装目录
221223

222224
```bash
223225
# Project > Session > Global > System
224-
$PWD/.vfox/sdks/nodejs/bin:~/.vfox/tmp/<pid>/nodejs/bin:~/.vfox/sdks/nodejs/bin:/usr/bin:...
226+
$PWD/.vfox/sdks/nodejs/bin:~/.vfox/tmp/<pid>/sdks/nodejs/bin:~/.vfox/sdks/nodejs/bin:/usr/bin:...
225227
```
226228

227229
:::

docs/zh-hans/usage/core-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ vfox unuse [options] <sdk-name>
128128
:::
129129

130130
::: warning 效果
131-
使用 `unuse` 后,SDK 将不再在指定作用域中处于活动状态。如果 SDK 在其他作用域中配置,那些将根据 vfox 的作用域层次结构优先生效(Session > Project > Global)。
131+
使用 `unuse` 后,SDK 将不再在指定作用域中处于活动状态。如果 SDK 在其他作用域中配置,那些将根据 vfox 的作用域层次结构优先生效(Project > Session > Global)。
132132
:::
133133

134134
## Uninstall

internal/sdk/legacy_parse_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2026 Han Li and contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sdk
18+
19+
import (
20+
"os"
21+
"path/filepath"
22+
"testing"
23+
24+
"github.com/version-fox/vfox/internal/config"
25+
"github.com/version-fox/vfox/internal/env"
26+
"github.com/version-fox/vfox/internal/plugin"
27+
)
28+
29+
func TestSdkParseLegacyFile_UsesDeclaredLegacyFilenames(t *testing.T) {
30+
envContext := &env.RuntimeEnvContext{
31+
UserConfig: config.DefaultConfig,
32+
RuntimeVersion: "test",
33+
}
34+
35+
plug, err := plugin.CreatePlugin(filepath.Join("..", "plugin", "testdata", "plugins", "java_with_metadata"), envContext)
36+
if err != nil {
37+
t.Fatalf("create plugin: %v", err)
38+
}
39+
defer plug.Close()
40+
41+
projectDir := t.TempDir()
42+
if err := os.WriteFile(filepath.Join(projectDir, ".node-version"), []byte("14.17.0\n"), 0644); err != nil {
43+
t.Fatalf("write legacy file: %v", err)
44+
}
45+
46+
sdk := &impl{
47+
Name: "java_with_metadata",
48+
envContext: envContext,
49+
plugin: plug,
50+
}
51+
52+
version, err := sdk.ParseLegacyFile(projectDir)
53+
if err != nil {
54+
t.Fatalf("parse legacy file: %v", err)
55+
}
56+
if version != "14.17.0" {
57+
t.Fatalf("expected legacy file version 14.17.0, got %q", version)
58+
}
59+
}

internal/sdk/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func (b *impl) Current() Version {
717717
// It returns the first valid version found.
718718
func (b *impl) ParseLegacyFile(path string) (Version, error) {
719719
legacyFilenames := b.plugin.Metadata.LegacyFilenames
720-
if len(legacyFilenames) > 0 {
720+
if len(legacyFilenames) == 0 {
721721
return "", nil
722722
}
723723
if !b.plugin.HasFunction("ParseLegacyFile") {

0 commit comments

Comments
 (0)