/
plugins_command.go
43 lines (32 loc) · 1.08 KB
/
plugins_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cli
import (
"fmt"
"github.com/choria-io/fisk"
"github.com/nats-io/natscli/plugins"
)
type pluginsCmd struct {
name string
command string
force bool
}
func configurePluginCommand(app commandHost) {
c := &pluginsCmd{}
cmd := app.Command("plugins", "Manage plugins").Hidden()
register := cmd.Commandf("register", "Registers a new plugin").Action(c.registerAction)
register.Arg("name", "The top level name to register the command as").Required().StringVar(&c.name)
register.Arg("command", "The command the provides the plugins").Required().ExistingFileVar(&c.command)
register.Flag("force", "Overwrite existing plugins").UnNegatableBoolVar(&c.force)
}
func init() {
registerCommand("plugins", 18, configurePluginCommand)
}
func (c *pluginsCmd) registerAction(_ *fisk.ParseContext) error {
fmt.Println("WARNING: Plugins support is experimental and not officially supported")
fmt.Println()
err := plugins.Register(c.name, c.command, c.force)
if err != nil {
return err
}
fmt.Printf("Plugin %s using command %s was added or updated\n", c.name, c.command)
return nil
}