Skip to content

Commit 1bc0405

Browse files
feat: add vfox install --yes option for quick installation (#507)
Co-authored-by: Jiacheng <jiacheng.li@bytedance.com>
1 parent 85f3af6 commit 1bc0405

File tree

6 files changed

+68
-30
lines changed

6 files changed

+68
-30
lines changed

cmd/commands/install.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ var Install = &cli.Command{
4141
Aliases: []string{"a"},
4242
Usage: "Install all SDK versions recorded in .tool-versions",
4343
},
44+
&cli.BoolFlag{
45+
Name: "yes",
46+
Aliases: []string{"y"},
47+
Usage: "Quick installation, skip interactive prompts",
48+
},
4449
},
4550
Action: installCmd,
4651
Category: CategorySDK,
4752
}
4853

4954
func installCmd(ctx *cli.Context) error {
55+
yes := ctx.Bool("yes")
56+
5057
if ctx.Bool("all") {
51-
return installAll()
58+
return installAll(yes)
5259
}
5360

5461
args := ctx.Args()
@@ -78,7 +85,9 @@ func installCmd(ctx *cli.Context) error {
7885
name = strings.ToLower(argArr[0])
7986
version = ""
8087
}
81-
sdk, err := manager.LookupSdkWithInstall(name)
88+
89+
sdk, err := manager.LookupSdkWithInstall(name, yes)
90+
8291
if err != nil {
8392
errorStore.AddAndShow(name, err)
8493
continue
@@ -115,7 +124,7 @@ func installCmd(ctx *cli.Context) error {
115124
return nil
116125
}
117126

118-
func installAll() error {
127+
func installAll(autoConfirm bool) error {
119128
manager := internal.NewSdkManager()
120129
defer manager.Close()
121130

@@ -131,10 +140,13 @@ func installAll() error {
131140
fmt.Println("Install the following plugins and SDKs:")
132141
printPlugin(plugins, nil)
133142
printSdk(sdks, nil)
134-
if result, _ := pterm.DefaultInteractiveConfirm.
135-
WithDefaultValue(true).
136-
Show("Do you want to install these plugins and SDKs?"); !result {
137-
return nil
143+
144+
if !autoConfirm {
145+
if result, _ := pterm.DefaultInteractiveConfirm.
146+
WithDefaultValue(true).
147+
Show("Do you want to install these plugins and SDKs?"); !result {
148+
return nil
149+
}
138150
}
139151

140152
var (

cmd/commands/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Search = &cli.Command{
4040
func RunSearch(sdkName string, availableArgs []string) error {
4141
manager := internal.NewSdkManager()
4242
defer manager.Close()
43-
source, err := manager.LookupSdkWithInstall(sdkName)
43+
source, err := manager.LookupSdkWithInstall(sdkName, false)
4444
if err != nil {
4545
return fmt.Errorf("%s not supported, error: %w", sdkName, err)
4646
}

docs/usage/core-commands.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,25 @@ vfox i <sdk-name>@<version>
5151
**Options**
5252

5353
- `-a, --all`: Install all SDK versions recorded in .tool-versions
54+
- `-y, --yes`: Quick installation, skip interactive prompts​
5455

5556
::: tip
5657
You can install multiple SDKs at the same time by separating them with space.
5758

5859
```shell
5960
vfox install nodejs@20 golang ...
6061
```
62+
63+
:::
64+
65+
::: tip
66+
Quick installation, skip interactive prompts​​
67+
68+
```shell
69+
vfox install --yes nodejs@20
70+
vfox install --yes --all
71+
```
72+
6173
:::
6274

6375
## Use

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,25 @@ vfox i <sdk-name>@<version>
5353
**选项**
5454

5555
- `-a, --all`: 安装 .tool-versions 中记录的所有 SDK 版本
56+
- `-y, --yes`: 直接安装,跳过确认提示
5657

5758
::: tip 自动安装
5859
你可以一次性安装多个 SDK,通过空格分隔。
5960

6061
```shell
6162
vfox install nodejs@20 golang ...
6263
```
64+
65+
:::
66+
67+
::: tip
68+
直接安装,跳过确认提示
69+
70+
```shell
71+
vfox install --yes nodejs@20
72+
vfox install --yes --all
73+
```
74+
6375
:::
6476

6577
## Use

internal/manager.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,33 +265,35 @@ func (m *Manager) ResolveVersion(sdkName string, version base.Version) base.Vers
265265
return version
266266
}
267267

268-
func (m *Manager) LookupSdkWithInstall(name string) (*Sdk, error) {
268+
func (m *Manager) LookupSdkWithInstall(name string, autoConfirm bool) (*Sdk, error) {
269269
source, err := m.LookupSdk(name)
270270
if err != nil {
271271
if errors.As(err, &NotFoundError{}) {
272-
fmt.Printf("[%s] not added yet, confirm that you want to use [%s]? \n", pterm.LightBlue(name), pterm.LightRed(name))
273-
if result, _ := pterm.DefaultInteractiveConfirm.
274-
WithTextStyle(&pterm.ThemeDefault.DefaultText).
275-
WithConfirmStyle(&pterm.ThemeDefault.DefaultText).
276-
WithRejectStyle(&pterm.ThemeDefault.DefaultText).
277-
WithDefaultText("Please confirm").
278-
Show(); result {
279-
280-
manifest, err := m.fetchPluginManifest(m.GetRegistryAddress(name + ".json"))
281-
if err != nil {
282-
if errors.Is(err, ManifestNotFound) {
283-
return nil, fmt.Errorf("[%s] not found in remote registry, please check the name", pterm.LightRed(name))
284-
}
285-
return nil, err
272+
if autoConfirm {
273+
fmt.Printf("[%s] not added yet, automatically proceeding with installation.\n", pterm.LightBlue(name))
274+
} else {
275+
fmt.Printf("[%s] not added yet, confirm that you want to use [%s]? \n", pterm.LightBlue(name), pterm.LightRed(name))
276+
result, _ := pterm.DefaultInteractiveConfirm.
277+
WithTextStyle(&pterm.ThemeDefault.DefaultText).
278+
WithConfirmStyle(&pterm.ThemeDefault.DefaultText).
279+
WithRejectStyle(&pterm.ThemeDefault.DefaultText).
280+
WithDefaultText("Please confirm").
281+
Show()
282+
if !result {
283+
return nil, cli.Exit("", 1)
286284
}
287-
288-
if err = m.Add(manifest.Name, manifest.DownloadUrl, ""); err != nil {
289-
return nil, err
285+
}
286+
manifest, err := m.fetchPluginManifest(m.GetRegistryAddress(name + ".json"))
287+
if err != nil {
288+
if errors.Is(err, ManifestNotFound) {
289+
return nil, fmt.Errorf("[%s] not found in remote registry, please check the name", pterm.LightRed(name))
290290
}
291-
return m.LookupSdk(manifest.Name)
292-
} else {
293-
return nil, cli.Exit("", 1)
291+
return nil, err
292+
}
293+
if err = m.Add(manifest.Name, manifest.DownloadUrl, ""); err != nil {
294+
return nil, err
294295
}
296+
return m.LookupSdk(manifest.Name)
295297
}
296298
return nil, fmt.Errorf("%s not supported, error: %w", name, err)
297299
} else {

internal/shell/clink_vfox.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ clink.argmatcher('vfox'):nofiles():setdelayinit(function(vfox)
7878
local vfox_install = clink.argmatcher():nofiles():addarg({
7979
onadvance = function() return 0 end,
8080
vfox_sdk_func,
81-
}):addflags('--all', '-a', '--help', '-h')
81+
}):addflags('--all', '-a', '--yes', '-y', '--help', '-h')
8282

8383
vfox:addarg(
8484
'add' .. clink.argmatcher():nofiles():addarg({

0 commit comments

Comments
 (0)