Make subcommands match new command info form

This commit is contained in:
sophia 2021-04-15 11:21:43 -05:00 committed by Paul Hinze
parent e4f6c403e1
commit fb6842a3c0
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
4 changed files with 16 additions and 79 deletions

View File

@ -36,31 +36,11 @@ func (c *Command) Documentation() (*docs.Documentation, error) {
return doc, nil
}
// SynopsisFunc implements component.Command
func (c *Command) SynopsisFunc() interface{} {
return c.Synopsis
}
// HelpFunc implements component.Command
func (c *Command) HelpFunc() interface{} {
return c.Help
}
// FlagsFunc implements component.Command
func (c *Command) FlagsFunc() interface{} {
return c.Flags
}
// ExecuteFunc implements component.Command
func (c *Command) ExecuteFunc() interface{} {
return c.Execute
}
// SubcommandFunc implements component.Command
func (c *Command) SubcommandsFunc() interface{} {
return c.Subcommands
}
// CommandInfoFunc implements component.Command
func (c *Command) CommandInfoFunc() interface{} {
return c.CommandInfo
@ -68,10 +48,11 @@ func (c *Command) CommandInfoFunc() interface{} {
func (c *Command) CommandInfo() *plugincore.CommandInfo {
return &plugincore.CommandInfo{
Name: "myplugin",
Help: c.Help(),
Synopsis: c.Synopsis(),
Flags: c.Flags(),
Name: "myplugin",
Help: c.Help(),
Synopsis: c.Synopsis(),
Flags: c.Flags(),
Subcommands: c.Subcommands(),
}
}
@ -87,10 +68,12 @@ func (c *Command) Flags() []*option.Option {
return []*option.Option{}
}
func (c *Command) Subcommands() []component.Command {
return []component.Command{
&DoThing{Command: c},
&Info{Command: c},
func (c *Command) Subcommands() []*plugincore.CommandInfo {
doThingCmd := &DoThing{Command: c}
infoCmd := &Info{Command: c}
return []*plugincore.CommandInfo{
doThingCmd.CommandInfo(),
infoCmd.CommandInfo(),
}
}

View File

@ -34,31 +34,11 @@ func (c *DoThing) Documentation() (*docs.Documentation, error) {
return doc, nil
}
// SynopsisFunc implements component.Command
func (c *DoThing) SynopsisFunc() interface{} {
return c.Synopsis
}
// HelpFunc implements component.Command
func (c *DoThing) HelpFunc() interface{} {
return c.Help
}
// FlagsFunc implements component.Command
func (c *DoThing) FlagsFunc() interface{} {
return c.Flags
}
// ExecuteFunc implements component.Command
func (c *DoThing) ExecuteFunc() interface{} {
return c.Execute
}
// SubcommandFunc implements component.Command
func (c *DoThing) SubcommandsFunc() interface{} {
return c.Subcommands
}
// CommandInfoFunc implements component.Command
func (c *DoThing) CommandInfoFunc() interface{} {
return c.CommandInfo
@ -66,7 +46,7 @@ func (c *DoThing) CommandInfoFunc() interface{} {
func (c *DoThing) CommandInfo() *plugincore.CommandInfo {
return &plugincore.CommandInfo{
Name: []string{"myplugin", "donothing"},
Name: "donothing",
Help: c.Help(),
Synopsis: c.Synopsis(),
Flags: c.Flags(),
@ -95,10 +75,6 @@ func (c *DoThing) Flags() []*option.Option {
return []*option.Option{booltest, stringflag}
}
func (c *DoThing) Subcommands() []string {
return []string{}
}
func (c *DoThing) Execute(trm terminal.UI) int64 {
trm.Output("Tricked ya! I actually do nothing :P")
return 0

View File

@ -36,31 +36,11 @@ func (c *Info) Documentation() (*docs.Documentation, error) {
return doc, nil
}
// SynopsisFunc implements component.Command
func (c *Info) SynopsisFunc() interface{} {
return c.Synopsis
}
// HelpFunc implements component.Command
func (c *Info) HelpFunc() interface{} {
return c.Help
}
// FlagsFunc implements component.Command
func (c *Info) FlagsFunc() interface{} {
return c.Flags
}
// ExecuteFunc implements component.Command
func (c *Info) ExecuteFunc() interface{} {
return c.Execute
}
// SubcommandFunc implements component.Command
func (c *Info) SubcommandsFunc() interface{} {
return c.Subcommands
}
// CommandInfoFunc implements component.Command
func (c *Info) CommandInfoFunc() interface{} {
return c.CommandInfo
@ -68,7 +48,7 @@ func (c *Info) CommandInfoFunc() interface{} {
func (c *Info) CommandInfo() *plugincore.CommandInfo {
return &plugincore.CommandInfo{
Name: []string{"myplugin", "info"},
Name: "info",
Help: c.Help(),
Synopsis: c.Synopsis(),
Flags: c.Flags(),
@ -87,10 +67,6 @@ func (c *Info) Flags() []*option.Option {
return []*option.Option{}
}
func (c *Info) Subcommands() []string {
return []string{}
}
func (c *Info) Execute(trm terminal.UI, env plugincore.Project) int64 {
mn, _ := env.MachineNames()
trm.Output("\nMachines in this project")

View File

@ -3,6 +3,7 @@ package core
import (
"context"
"io"
"strings"
"sync"
"github.com/golang/protobuf/proto"
@ -199,7 +200,8 @@ func (p *Project) specializeComponent(c *Component) (cmp plugin.PluginMetadata,
func (p *Project) Run(ctx context.Context, task *vagrant_server.Task) (err error) {
p.logger.Debug("running new task", "project", p, "task", task)
cmd, err := p.basis.component(ctx, component.CommandType, task.Component.Name)
componentName := strings.Split(task.Component.Name, " ")[0]
cmd, err := p.basis.component(ctx, component.CommandType, componentName)
if err != nil {
return err
}