Skip to content

Commit

Permalink
alpha: support for stringarray in plugin commmand
Browse files Browse the repository at this point in the history
  • Loading branch information
23doors committed Apr 28, 2022
1 parent d0a558d commit 318e678
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cmd/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *Executor) commandPreRun(ctx context.Context) error {

v, err := e.opts.valueOpts.MergeValues(ctx, filepath.Dir(cfgPath), getter.All())
if err != nil {
if isHelp {
if isHelp && !e.rootCmd.PersistentFlags().Lookup("values").Changed {
return nil
}

Expand Down Expand Up @@ -205,6 +205,15 @@ func (e *Executor) addPluginsCommands() error {
case plugins.CommandValueTypeString:
def, _ := f.Default.(string)
f.Value = flags.StringP(f.Name, f.Short, def, f.Usage)
case plugins.CommandValueTypeStringArray:
def, _ := f.Default.([]interface{})
defStr := make([]string, len(def))

for i, v := range def {
defStr[i] = v.(string)
}

f.Value = flags.StringArrayP(f.Name, f.Short, defStr, f.Usage)
}

if f.Required {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/mholt/archiver/v3 v3.5.1
github.com/mitchellh/go-homedir v1.1.0
github.com/otiai10/copy v1.7.0
github.com/outblocks/outblocks-plugin-go v0.0.0-20220427125140-5c3ad920eb15
github.com/outblocks/outblocks-plugin-go v0.0.0-20220428150459-262b053acc7f
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.41
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/outblocks/outblocks-plugin-go v0.0.0-20220427125140-5c3ad920eb15 h1:+QY8R9j4C2cO+8cN/DqNBg312X9baO3VRqWh/C1NUBk=
github.com/outblocks/outblocks-plugin-go v0.0.0-20220427125140-5c3ad920eb15/go.mod h1:tcD3iwXc4UZ0H0ad9wvY41ZOqbG2UJ6bbl1Ha+/eyJc=
github.com/outblocks/outblocks-plugin-go v0.0.0-20220428150459-262b053acc7f h1:cS5UIYIi/BnKLHYxuqQS2d91sPZ33AoyJGGbCEAu9G4=
github.com/outblocks/outblocks-plugin-go v0.0.0-20220428150459-262b053acc7f/go.mod h1:tcD3iwXc4UZ0H0ad9wvY41ZOqbG2UJ6bbl1Ha+/eyJc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
Expand Down
14 changes: 13 additions & 1 deletion pkg/plugins/plugin_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
CommandValueTypeBool CommandValueType = iota + 1
CommandValueTypeString
CommandValueTypeInt
CommandValueTypeStringArray
)

type CommandInputType int
Expand All @@ -26,7 +27,7 @@ const (
)

var (
CommandValueTypes = []string{"str", "string", "bool", "boolean", "int", "integer"}
CommandValueTypes = []string{"str", "string", "bool", "boolean", "int", "integer", "strings", "stringarray"}
CommandInputTypes = []string{"app_states", "dependency_states", "plugin_state"}
)

Expand Down Expand Up @@ -106,6 +107,15 @@ func (p *PluginCommandFlag) Val() interface{} {
return *(p.Value.(*string))
case CommandValueTypeInt:
return *(p.Value.(*int))
case CommandValueTypeStringArray:
v := *(p.Value.(*[]string))
ret := make([]interface{}, len(v))

for i, val := range v {
ret[i] = val
}

return ret
}

return nil
Expand All @@ -123,6 +133,8 @@ func (p *PluginCommandFlag) ValueType() CommandValueType {
p.typ = CommandValueTypeInt
case "str", "string":
p.typ = CommandValueTypeString
case "stringarray", "strings":
p.typ = CommandValueTypeStringArray
default:
panic(fmt.Sprintf("unknown command value type: %s", p.Type))
}
Expand Down

0 comments on commit 318e678

Please sign in to comment.