Skip to content

Commit

Permalink
feat: support adding multiple plugins at once (#203)
Browse files Browse the repository at this point in the history
* feat: support addCmd add multiple parameters for faster

* feat: add config operation, config ls, config storage --sdk-path=D:/vfox/

* feat: add config command, ls, unset, proxy.url etc.

* feat: add config command, ls, unset, proxy.url etc.

* Update cmd/commands/add.go

* Update docs/zh-hans/usage/all-commands.md

* feat: add config command, ls, unset, proxy.url etc.

* mod: minor adjustment

* doc: update

---------

Co-authored-by: 野声 <[email protected]>
Co-authored-by: lihan <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent f75b6e2 commit 768ce6a
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ $ node -v
## 路线图

我们未来的计划以及高度优先的功能和增强功能是:
- [X] 重构插件机制:
- 增加插件模板, 允许多文件开发插件
- [X] 重构插件机制:
- 增加插件模板, 允许多文件开发插件
- 增加全局注册表(类似于:`NPM Registry``Scoop Main Bucket`), 为插件分发提供统一入口
- 拆分现有的插件仓库, 一个插件一个仓库
- [X] 允许切换注册表地址
Expand Down
33 changes: 27 additions & 6 deletions cmd/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package commands

import (
"errors"
"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
)

var Add = &cli.Command{
Name: "add",
Usage: "Add a plugin",
Usage: "Add a plugin or plugins",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "source",
Expand All @@ -41,10 +42,30 @@ var Add = &cli.Command{

// addCmd is the command to add a plugin of sdk
func addCmd(ctx *cli.Context) error {
args := ctx.Args()
var errStr = ""
var source = ""
var alias = ""
var err error

if args.Len() == 1 {
source = ctx.String("source")
alias = ctx.String("alias")
}

manager := internal.NewSdkManager()
defer manager.Close()
sdkName := ctx.Args().First()
source := ctx.String("source")
alias := ctx.String("alias")
return manager.Add(sdkName, source, alias)
for _, sdkName := range args.Slice() {
err = manager.Add(sdkName, source, alias)
if err != nil {
errStr += err.Error() + "\r\n"
continue
}
}
manager.Close()
if errStr != "" {
err = errors.New(errStr)
return err
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/commands/available.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func availableCmd(ctx *cli.Context) error {
WithHasHeader().
WithSeparator("\t ").
WithData(data).Render()
pterm.Printf("Please use %s to install plugin\n", pterm.LightBlue("vfox add <plugin name>"))
pterm.Printf("Please use %s to install plugins\n", pterm.LightBlue("vfox add <plugin name>"))
return nil

}
6 changes: 5 additions & 1 deletion docs/plugins/create/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ Currently, VersionFox plugin testing is straightforward. You only need to place

## Publish to the public registry

`vfox` allows custom installation of plugins, such as `vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip`
`vfox` allows custom installation of plugins, such as:

```shell
vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip
```

In order to make it easier for your users, you can add the plugin to the public registry to list your plugin and easily install it with shorter commands, such as `vfox add nodejs`.

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/all-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```shell
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 add [--alias <sdk-name> --source <url/path> ] <plugin-name> Add a plugin or plugins from offical repository or custom source, --alias` and `--source` are not supported when adding multiple plugins.
vfox remove <sdk-name> Remove a plugin
vfox update [<sdk-name> | --all] Update a specified or all plugin(s)
vfox info <sdk-name> Show plugin info
Expand Down
11 changes: 9 additions & 2 deletions docs/usage/plugins-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,29 @@ Add a plugin from the official repository or a custom source.
**Usage**

```shell
vfox add [options] <plugin-name>
vfox add [options] <plugin-name> [<plugin-name2>...]
```

`plugin-name`: Plugin name, such as `nodejs`.
`plugin-name`: Plugin name, such as `nodejs`. You can install multiple plugins at once, separated by spaces.

**Options**

- `-a, --alias`: Set the plugin alias.
- `-s, --source`: Install the plugin from the specified path (can be a remote file or a local file).


::: warning
`--alias` and `--source` are not supported when adding multiple plugins.
:::

**Examples**

**Install plugin from the official repository**

```shell
$ vfox add --alias node nodejs

$ vfox add golang java nodejs
```

**Install custom plugin**
Expand Down
6 changes: 5 additions & 1 deletion docs/zh-hans/plugins/create/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ end

## 向官方插件存储库提交插件

vfox可以允许自定义安装插件,比如`vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip `
`vfox`可以允许自定义安装插件,比如:

```shell
vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip
```

为了使你的用户更轻松,你可以将插件添加到官方插件存储库中,以列出你的插件并使用较短的命令轻松安装,比如 `vfox add nodejs`

Expand Down
2 changes: 1 addition & 1 deletion docs/zh-hans/usage/all-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```shell
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 add [--alias <sdk-name> --source <url/path> ] <plugin-name> Add a plugin or plugins from offical repository or custom source, `--alias` and `--source` are not supported when adding multiple plugins.
vfox remove <sdk-name> Remove a plugin
vfox update [<sdk-name> | --all] Update a specified or all plugin(s)
vfox info <sdk-name> Show plugin info
Expand Down
10 changes: 8 additions & 2 deletions docs/zh-hans/usage/plugins-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,28 @@ vfox available
**用法**

```shell
vfox add [options] <plugin-name>
vfox add [options] <plugin-name> [<plugin-name2>...]
```
`plugin-name`: 插件名称, 如`nodejs`
`plugin-name`: 插件名称, 如`nodejs`可以同时安装多个插件, 用空格分隔。

**选项**
- `-a, --alias`: 设置插件别名。
- `-s, --source`: 安装指定路径下的插件(可以是远程文件也可以是本地文件)

::: warning 注意
`--alias``--source` 不支持在安装多个插件时使用。
:::

**例子**

**安装仓库插件**
```shell
$ vfox add --alias node nodejs

$ vfox add golang java nodejs
```


**安装自定义插件**
```shell
$ vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip custom-node
Expand Down
1 change: 1 addition & 0 deletions internal/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func (m *Manager) Add(pluginName, url, alias string) error {
return fmt.Errorf("plugin %s already exists", pname)
}

fmt.Printf("Fetching %s manifest... \n", pterm.Green(pname))
pluginManifest, err := m.fetchPluginManifest(m.GetRegistryAddress(pname + ".json"))
if err != nil {
return err
Expand Down

0 comments on commit 768ce6a

Please sign in to comment.