233 lines
5.2 KiB
Go
233 lines
5.2 KiB
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package hostsetscmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
"github.com/hashicorp/boundary/api/hostsets"
|
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
|
"github.com/hashicorp/boundary/internal/cmd/common"
|
|
"github.com/hashicorp/boundary/sdk/strutil"
|
|
"github.com/mitchellh/cli"
|
|
"github.com/posener/complete"
|
|
)
|
|
|
|
func initStaticFlags() {
|
|
flagsOnce.Do(func() {
|
|
extraFlags := extraStaticActionsFlagsMapFunc()
|
|
for k, v := range extraFlags {
|
|
flagsStaticMap[k] = append(flagsStaticMap[k], v...)
|
|
}
|
|
})
|
|
}
|
|
|
|
var (
|
|
_ cli.Command = (*StaticCommand)(nil)
|
|
_ cli.CommandAutocomplete = (*StaticCommand)(nil)
|
|
)
|
|
|
|
type StaticCommand struct {
|
|
*base.Command
|
|
|
|
Func string
|
|
|
|
plural string
|
|
}
|
|
|
|
func (c *StaticCommand) AutocompleteArgs() complete.Predictor {
|
|
initStaticFlags()
|
|
return complete.PredictAnything
|
|
}
|
|
|
|
func (c *StaticCommand) AutocompleteFlags() complete.Flags {
|
|
initStaticFlags()
|
|
return c.Flags().Completions()
|
|
}
|
|
|
|
func (c *StaticCommand) Synopsis() string {
|
|
if extra := extraStaticSynopsisFunc(c); extra != "" {
|
|
return extra
|
|
}
|
|
|
|
synopsisStr := "host set"
|
|
|
|
synopsisStr = fmt.Sprintf("%s %s", "static-type", synopsisStr)
|
|
|
|
return common.SynopsisFunc(c.Func, synopsisStr)
|
|
}
|
|
|
|
func (c *StaticCommand) Help() string {
|
|
initStaticFlags()
|
|
|
|
var helpStr string
|
|
helpMap := common.HelpMap("host set")
|
|
|
|
switch c.Func {
|
|
default:
|
|
|
|
helpStr = c.extraStaticHelpFunc(helpMap)
|
|
}
|
|
|
|
// Keep linter from complaining if we don't actually generate code using it
|
|
_ = helpMap
|
|
return helpStr
|
|
}
|
|
|
|
var flagsStaticMap = map[string][]string{
|
|
|
|
"create": {"host-catalog-id", "name", "description"},
|
|
|
|
"update": {"id", "name", "description", "version"},
|
|
}
|
|
|
|
func (c *StaticCommand) Flags() *base.FlagSets {
|
|
if len(flagsStaticMap[c.Func]) == 0 {
|
|
return c.FlagSet(base.FlagSetNone)
|
|
}
|
|
|
|
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
|
|
f := set.NewFlagSet("Command Options")
|
|
common.PopulateCommonFlags(c.Command, f, "static-type host set", flagsStaticMap[c.Func])
|
|
|
|
extraStaticFlagsFunc(c, set, f)
|
|
|
|
return set
|
|
}
|
|
|
|
func (c *StaticCommand) Run(args []string) int {
|
|
initStaticFlags()
|
|
|
|
switch c.Func {
|
|
case "":
|
|
return cli.RunResultHelp
|
|
}
|
|
|
|
c.plural = "static-type host set"
|
|
switch c.Func {
|
|
case "list":
|
|
c.plural = "static-type host sets"
|
|
}
|
|
|
|
f := c.Flags()
|
|
|
|
if err := f.Parse(args); err != nil {
|
|
c.PrintCliError(err)
|
|
return 1
|
|
}
|
|
|
|
if strutil.StrListContains(flagsStaticMap[c.Func], "id") && c.FlagId == "" {
|
|
c.PrintCliError(errors.New("ID is required but not passed in via -id"))
|
|
return 1
|
|
}
|
|
|
|
var opts []hostsets.Option
|
|
|
|
if strutil.StrListContains(flagsStaticMap[c.Func], "host-catalog-id") {
|
|
switch c.Func {
|
|
case "create":
|
|
if c.FlagHostCatalogId == "" {
|
|
c.PrintCliError(errors.New("HostCatalog ID must be passed in via -host-catalog-id or BOUNDARY_HOST_CATALOG_ID"))
|
|
return 1
|
|
}
|
|
}
|
|
}
|
|
|
|
client, err := c.Client()
|
|
if err != nil {
|
|
c.PrintCliError(fmt.Errorf("Error creating API client: %s", err.Error()))
|
|
return 2
|
|
}
|
|
hostsetsClient := hostsets.NewClient(client)
|
|
|
|
switch c.FlagName {
|
|
case "":
|
|
case "null":
|
|
opts = append(opts, hostsets.DefaultName())
|
|
default:
|
|
opts = append(opts, hostsets.WithName(c.FlagName))
|
|
}
|
|
|
|
switch c.FlagDescription {
|
|
case "":
|
|
case "null":
|
|
opts = append(opts, hostsets.DefaultDescription())
|
|
default:
|
|
opts = append(opts, hostsets.WithDescription(c.FlagDescription))
|
|
}
|
|
|
|
var version uint32
|
|
|
|
switch c.Func {
|
|
case "update":
|
|
switch c.FlagVersion {
|
|
case 0:
|
|
opts = append(opts, hostsets.WithAutomaticVersioning(true))
|
|
default:
|
|
version = uint32(c.FlagVersion)
|
|
}
|
|
}
|
|
|
|
if ret := extraStaticFlagsHandlingFunc(c, &opts); ret != 0 {
|
|
return ret
|
|
}
|
|
|
|
var result api.GenericResult
|
|
|
|
switch c.Func {
|
|
|
|
case "create":
|
|
result, err = hostsetsClient.Create(c.Context, c.FlagHostCatalogId, opts...)
|
|
|
|
case "update":
|
|
result, err = hostsetsClient.Update(c.Context, c.FlagId, version, opts...)
|
|
|
|
}
|
|
|
|
result, err = executeExtraStaticActions(c, result, err, hostsetsClient, version, opts)
|
|
|
|
if err != nil {
|
|
if apiErr := api.AsServerError(err); apiErr != nil {
|
|
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural))
|
|
return 1
|
|
}
|
|
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
|
return 2
|
|
}
|
|
|
|
output, err := printCustomStaticActionOutput(c)
|
|
if err != nil {
|
|
c.PrintCliError(err)
|
|
return 1
|
|
}
|
|
if output {
|
|
return 0
|
|
}
|
|
|
|
switch c.Func {
|
|
}
|
|
|
|
item := result.GetItem().(*hostsets.HostSet)
|
|
switch base.Format(c.UI) {
|
|
case "table":
|
|
c.UI.Output(printItemTable(item))
|
|
|
|
case "json":
|
|
return c.PrintJsonItem(result, item)
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
var (
|
|
extraStaticActionsFlagsMapFunc = func() map[string][]string { return nil }
|
|
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
|
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
|
extraStaticFlagsHandlingFunc = func(*StaticCommand, *[]hostsets.Option) int { return 0 }
|
|
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *hostsets.Client, _ uint32, _ []hostsets.Option) (api.GenericResult, error) {
|
|
return inResult, inErr
|
|
}
|
|
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
|
)
|