Pull over CombinedSliceFlagValue from WIP plugin-hostcatalogs (#1582)
I've pulled over files as-is for the most part so this also pulls over some common attribute/secret flags but it's not worth dealing with the merge later...
This commit is contained in:
1 parent
5dd49871f9
commit
217adfc4d2
6 files changed
+925
-4
No files matched your search
@@ -68,6 +68,17 @@ type cmdInfo struct {
|
||||
// This allows the flags to be defined differently from the the attribute
|
||||
// names in the API.
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix bool
|
||||
|
||||
// HasGenericAttributes controls whether to generate flags for -attributes,
|
||||
// -attr, -string-attr, etc.
|
||||
HasGenericAttributes bool
|
||||
|
||||
// HasGenericSecrets controls whether to generate flags for -secrets,
|
||||
// -secret, -string-secret, etc.
|
||||
HasGenericSecrets bool
|
||||
|
||||
// IsPluginType controls whether standard plugin flags are generated
|
||||
IsPluginType bool
|
||||
}
|
||||
|
||||
var inputStructs = map[string][]*cmdInfo{
|
||||
|
||||
@@ -169,15 +169,17 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Help() string {
|
||||
}
|
||||
|
||||
var flags{{ camelCase .SubActionPrefix }}Map = map[string][]string{
|
||||
{{ range $i, $action := .StdActions }}
|
||||
{{ with $attrFlags := ", \"attributes\", \"attr\", \"string-attr\", \"bool-attr\", \"num-attr\"" }}
|
||||
{{ with $secretFlags := ", \"secrets\", \"secret\", \"string-secret\", \"bool-secret\", \"num-secret\"" }}
|
||||
{{ range $i, $action := $input.StdActions }}
|
||||
{{ if eq $action "create" }}
|
||||
"create": { "{{ kebabCase $input.Container }}-id", "name", "description" },
|
||||
"create": { "{{ kebabCase $input.Container }}-id", "name", "description" {{ if $input.IsPluginType }} , "plugin-id", "plugin-name" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} },
|
||||
{{ end }}
|
||||
{{ if eq $action "read" }}
|
||||
"read": {"id"},
|
||||
{{ end }}
|
||||
{{ if eq $action "update" }}
|
||||
"update": {"id", "name", "description" {{ if hasAction $input.VersionedActions "update" }}, "version" {{ end }} },
|
||||
"update": {"id", "name", "description" {{ if hasAction $input.VersionedActions "update" }}, "version" {{ end }} {{ if $input.HasGenericAttributes }} {{ $attrFlags }} {{ end }} {{ if $input.HasGenericSecrets }} {{ $secretFlags }} {{ end }} },
|
||||
{{ end }}
|
||||
{{ if eq $action "delete" }}
|
||||
"delete": {"id"},
|
||||
@@ -186,6 +188,8 @@ var flags{{ camelCase .SubActionPrefix }}Map = map[string][]string{
|
||||
"list": { "{{ kebabCase $input.Container }}-id", "filter" {{ if (eq $input.Container "Scope") }}, "recursive"{{ end }} },
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
func (c *{{ camelCase .SubActionPrefix }}Command) Flags() *base.FlagSets {
|
||||
@@ -197,6 +201,16 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Flags() *base.FlagSets {
|
||||
f := set.NewFlagSet("Command Options")
|
||||
common.PopulateCommonFlags(c.Command, f, "{{ if .SubActionPrefix }}{{ .SubActionPrefix }}-type {{ end }}{{ lowerSpaceCase .ResourceType }}", flags{{ camelCase .SubActionPrefix }}Map, c.Func)
|
||||
|
||||
{{ if .HasGenericAttributes }}
|
||||
f = set.NewFlagSet("Attribute Options")
|
||||
common.PopulateAttributeFlags(c.Command, f, flags{{ camelCase .SubActionPrefix }}Map, c.Func)
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasGenericSecrets }}
|
||||
f = set.NewFlagSet("Secrets Options")
|
||||
common.PopulateSecretFlags(c.Command, f, flags{{ camelCase .SubActionPrefix }}Map, c.Func)
|
||||
{{ end }}
|
||||
|
||||
extra{{ camelCase .SubActionPrefix }}FlagsFunc(c, set, f)
|
||||
|
||||
return set
|
||||
@@ -307,6 +321,19 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
opts = append(opts, {{ .Pkg }}.WithScopeName(c.FlagScopeName))
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .IsPluginType }}
|
||||
switch c.FlagPluginId {
|
||||
case "":
|
||||
default:
|
||||
opts = append(opts, {{ .Pkg }}.WithPluginId(c.FlagPluginId))
|
||||
}
|
||||
switch c.FlagPluginName {
|
||||
case "":
|
||||
default:
|
||||
opts = append(opts, {{ .Pkg }}.WithPluginName(c.FlagPluginName))
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
var version uint32
|
||||
{{ if .VersionedActions }}
|
||||
@@ -323,7 +350,41 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
if ok := extra{{ camelCase .SubActionPrefix }}FlagsHandlingFunc(c, f, &opts); !ok {
|
||||
{{ if .HasGenericAttributes }}
|
||||
if err := common.HandleAttributeFlags(
|
||||
c.Command,
|
||||
"attr",
|
||||
c.FlagAttributes,
|
||||
c.FlagAttrs,
|
||||
func() {
|
||||
opts = append(opts, {{ .Pkg }}.DefaultAttributes())
|
||||
},
|
||||
func(in map[string]interface{}) {
|
||||
opts = append(opts, {{ .Pkg }}.WithAttributes(in))
|
||||
}); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error evaluating attribute flags to: %s", err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .HasGenericSecrets }}
|
||||
if err := common.HandleAttributeFlags(
|
||||
c.Command,
|
||||
"secret",
|
||||
c.FlagSecrets,
|
||||
c.FlagScrts,
|
||||
func() {
|
||||
opts = append(opts, {{ .Pkg }}.DefaultSecrets())
|
||||
},
|
||||
func(in map[string]interface{}) {
|
||||
opts = append(opts, {{ .Pkg }}.WithSecrets(in))
|
||||
}); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error evaluating secret flags to: %s", err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
if ok := extra{{ camelCase .SubActionPrefix }}FlagsHandlingFunc(c, f, &opts, ); !ok {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user