From fb6842a3c0c01d1c07298ae37d64cf4cb2f28ec5 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 15 Apr 2021 11:21:43 -0500 Subject: [PATCH] Make subcommands match new command info form --- builtin/myplugin/commands/command.go | 39 ++++++++-------------------- builtin/myplugin/commands/dothing.go | 26 +------------------ builtin/myplugin/commands/info.go | 26 +------------------ internal/core/project.go | 4 ++- 4 files changed, 16 insertions(+), 79 deletions(-) diff --git a/builtin/myplugin/commands/command.go b/builtin/myplugin/commands/command.go index a6b07bb79..f038f26bd 100644 --- a/builtin/myplugin/commands/command.go +++ b/builtin/myplugin/commands/command.go @@ -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(), } } diff --git a/builtin/myplugin/commands/dothing.go b/builtin/myplugin/commands/dothing.go index ba535f04f..d99a89cd8 100644 --- a/builtin/myplugin/commands/dothing.go +++ b/builtin/myplugin/commands/dothing.go @@ -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 diff --git a/builtin/myplugin/commands/info.go b/builtin/myplugin/commands/info.go index 59bbf6f99..4fc7ca0a6 100644 --- a/builtin/myplugin/commands/info.go +++ b/builtin/myplugin/commands/info.go @@ -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") diff --git a/internal/core/project.go b/internal/core/project.go index 147e1041a..6628de62f 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -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 }