Skip to content

Commit

Permalink
feat: support update all installed plugins (#181)
Browse files Browse the repository at this point in the history
* feat: support update all installed plugins

run `vfox update --all` or `vfox update -a` to update all installed plugins

* docs: update `update` command usage docs
  • Loading branch information
gythialy authored Apr 8, 2024
1 parent 75a799d commit 16aa6b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
42 changes: 34 additions & 8 deletions cmd/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,49 @@
package commands

import (
"fmt"

"github.com/pterm/pterm"
"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
)

const allFlag = "all"

var Update = &cli.Command{
Name: "update",
Usage: "update specified plug-ins",
Name: "update",
Usage: "update specified plug-ins, --all/-a to update all installed plug-ins",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: allFlag,
Aliases: []string{"a"},
Usage: "all plugins flag",
},
},
Action: updateCmd,
}

func updateCmd(ctx *cli.Context) error {
args := ctx.Args()
l := args.Len()
if l < 1 {
return cli.Exit("invalid arguments", 1)
}
manager := internal.NewSdkManager()
defer manager.Close()
return manager.Update(args.First())
if ctx.Bool(allFlag) {
if sdks, err := manager.LoadAllSdk(); err == nil {
for sdk := range sdks {
if err = manager.Update(sdk); err != nil {
pterm.Println(fmt.Sprintf("update plugin(%s) failed, %s", sdk, err.Error()))
}
}
} else {
return cli.Exit(err.Error(), 1)
}
} else {
args := ctx.Args()
l := args.Len()
if l < 1 {
return cli.Exit("invalid arguments", 1)
}

return manager.Update(args.First())
}
return nil
}
5 changes: 3 additions & 2 deletions docs/usage/all-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ vfox remove <sdk-name>

## Update

Update plugin.
Update a specified or all plugin(s)

**Usage**

```shell
vfox update <sdk-name>
vfox update --all # update all installed plugins
```

## Overview
Expand All @@ -71,7 +72,7 @@ vfox - VersionFox, a tool for sdk version management
vfox available List all available plugins
vfox add [--alias <sdk-name> --source <url/path> ] <plugin-name> Add a plugin from offical repository or custom source
vfox remove <sdk-name> Remove a plugin
vfox update <sdk-name> Update a plugin
vfox update [<sdk-name> | --all] Update a specified or all plugin(s)
vfox info <sdk-name> Show plugin info
vfox search <sdk-name> Search available versions of a SDK
vfox install <sdk-name>@<version> Install the specified version of SDK
Expand Down
5 changes: 3 additions & 2 deletions docs/zh-hans/usage/all-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ vfox remove <sdk-name>

## Update

更新插件版本
更新指定的或全部已安装插件版本

**用法**

```shell
vfox update <sdk-name>
vfox update --all # 更新所有已安装插件
```


Expand All @@ -74,7 +75,7 @@ vfox - VersionFox, a tool for sdk version management
vfox available List all available plugins
vfox add [--alias <sdk-name> --source <url/path> ] <plugin-name> Add a plugin from offical repository or custom source
vfox remove <sdk-name> Remove a plugin
vfox update <sdk-name> Update a plugin
vfox update [<sdk-name> | --all] Update a specified or all plugin(s)
vfox info <sdk-name> Show plugin info
vfox search <sdk-name> Search available versions of a SDK
vfox install <sdk-name>@<version> Install the specified version of SDK
Expand Down

0 comments on commit 16aa6b8

Please sign in to comment.