Update builtins to use component command flag

This commit is contained in:
Chris Roberts 2022-01-19 10:20:23 -08:00 committed by Paul Hinze
parent 5115bc3fb3
commit bd9ba0654e
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
6 changed files with 49 additions and 47 deletions

View File

@ -1,7 +1,6 @@
package command
import (
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
plugincore "github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant-plugin-sdk/docs"
@ -99,13 +98,16 @@ func (c *Command) Help() string {
return "I'm here for testing, try running some subcommands"
}
func (c *Command) Flags() []*option.Option {
stringflag := option.New("hehe", option.StringType)
stringflag.Description = "a test flag for strings"
stringflag.DefaultStr = "message"
stringflag.Aliases = append(stringflag.Aliases, "hh")
return []*option.Option{stringflag}
func (c *Command) Flags() component.CommandFlags {
return []*component.CommandFlag{
{
LongName: "hehe",
ShortName: "",
Description: "a test flag for strings",
DefaultValue: "a default message",
Type: component.FlagString,
},
}
}
func (c *Command) Execute(trm terminal.UI, flags map[string]interface{}) int32 {

View File

@ -1,7 +1,6 @@
package command
import (
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/docs"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
@ -57,21 +56,26 @@ func (c *DoThing) Synopsis() string {
}
func (c *DoThing) Help() string {
return "I do really important work"
return "Usage: vagrant myplugin dothing"
}
func (c *DoThing) Flags() []*option.Option {
booltest := option.New("booltest", option.BoolType)
booltest.Description = "a test flag for bools"
booltest.DefaultStr = "true"
booltest.Aliases = append(booltest.Aliases, "bt")
stringflag := option.New("stringflag", option.StringType)
stringflag.Description = "a test flag for strings"
stringflag.DefaultStr = "message"
stringflag.Aliases = append(stringflag.Aliases, "sf")
return []*option.Option{booltest, stringflag}
func (c *DoThing) Flags() component.CommandFlags {
return []*component.CommandFlag{
{
LongName: "booltest",
ShortName: "b",
Description: "test flag for bools",
DefaultValue: "true",
Type: component.FlagBool,
},
{
LongName: "stringflag",
ShortName: "s",
Description: "test flag for strings",
DefaultValue: "a default message value",
Type: component.FlagString,
},
}
}
func (c *DoThing) Execute(trm terminal.UI, flags map[string]interface{}) int32 {

View File

@ -1,7 +1,6 @@
package command
import (
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
@ -40,8 +39,8 @@ func (c *Host) Help() string {
return c.Synopsis()
}
func (c *Host) Flags() []*option.Option {
return []*option.Option{}
func (c *Host) Flags() component.CommandFlags {
return []*component.CommandFlag{}
}
func (c *Host) Execute(trm terminal.UI, project core.Project) int32 {

View File

@ -3,7 +3,6 @@ package command
import (
"strings"
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
plugincore "github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant-plugin-sdk/docs"
@ -63,8 +62,8 @@ func (c *Info) Help() string {
return "Output some project information!"
}
func (c *Info) Flags() []*option.Option {
return []*option.Option{}
func (c *Info) Flags() component.CommandFlags {
return []*component.CommandFlag{}
}
func (c *Info) Execute(trm terminal.UI, p plugincore.Project) int32 {

View File

@ -1,7 +1,6 @@
package command
import (
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/docs"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
@ -60,8 +59,8 @@ func (c *Interactive) Help() string {
return "Test out interactive input!"
}
func (c *Interactive) Flags() []*option.Option {
return []*option.Option{}
func (c *Interactive) Flags() component.CommandFlags {
return []*component.CommandFlag{}
}
func (c *Interactive) Execute(trm terminal.UI) int32 {

View File

@ -3,7 +3,6 @@ package otherplugin
import (
"strings"
"github.com/DavidGamba/go-getoptions/option"
"github.com/hashicorp/vagrant-plugin-sdk/component"
plugincore "github.com/hashicorp/vagrant-plugin-sdk/core"
@ -45,12 +44,12 @@ func (c *Command) CommandInfo() *component.CommandInfo {
Name: "otherplugin",
Help: "HELP MEEEEE!",
Synopsis: "This command does stuff",
Flags: []*option.Option{
&option.Option{
Name: "thing",
OptType: option.StringType,
Flags: []*component.CommandFlag{
{
LongName: "thing",
Description: "a thing flag",
DefaultStr: "I'm a thing!",
DefaultValue: "I'm a thing!",
Type: component.FlagString,
},
},
Subcommands: []*component.CommandInfo{
@ -58,13 +57,13 @@ func (c *Command) CommandInfo() *component.CommandInfo {
Name: "info",
Help: "Shows info",
Synopsis: "IT. SHOWS. INFO.",
Flags: []*option.Option{},
Flags: []*component.CommandFlag{},
Subcommands: []*component.CommandInfo{
&component.CommandInfo{
Name: "ofni",
Help: "Shows ofni",
Synopsis: "BIZZARO info",
Flags: []*option.Option{},
Flags: []*component.CommandFlag{},
},
},
},
@ -72,12 +71,12 @@ func (c *Command) CommandInfo() *component.CommandInfo {
Name: "dothing",
Help: "Does thing",
Synopsis: "Does this super great thing!",
Flags: []*option.Option{
&option.Option{
OptType: option.StringType,
Name: "stringflag",
Flags: []*component.CommandFlag{
{
LongName: "stringflag",
Description: "a test flag",
DefaultStr: "I'm a string!",
DefaultValue: "I'm a string!",
Type: component.FlagString,
},
},
},
@ -85,7 +84,7 @@ func (c *Command) CommandInfo() *component.CommandInfo {
Name: "use-host",
Help: "Executes a host capability",
Synopsis: "Executes a host capability",
Flags: []*option.Option{},
Flags: []*component.CommandFlag{},
},
},
}