stash/pkg/plugin/args.go

42 lines
898 B
Go
Raw Normal View History

2020-08-08 02:05:35 +00:00
package plugin
type PluginArgInput struct {
Key string `json:"key"`
Value *PluginValueInput `json:"value"`
}
type PluginValueInput struct {
Str *string `json:"str"`
I *int `json:"i"`
B *bool `json:"b"`
F *float64 `json:"f"`
O []*PluginArgInput `json:"o"`
A []*PluginValueInput `json:"a"`
}
2020-08-08 02:05:35 +00:00
func findArg(args []*PluginArgInput, name string) *PluginArgInput {
2020-08-08 02:05:35 +00:00
for _, v := range args {
if v.Key == name {
return v
}
}
return nil
}
func applyDefaultArgs(args []*PluginArgInput, defaultArgs map[string]string) []*PluginArgInput {
2020-08-08 02:05:35 +00:00
for k, v := range defaultArgs {
if arg := findArg(args, k); arg == nil {
v := v // Copy v, because it's being exported out of the loop
args = append(args, &PluginArgInput{
2020-08-08 02:05:35 +00:00
Key: k,
Value: &PluginValueInput{
2020-08-08 02:05:35 +00:00
Str: &v,
},
})
}
}
return args
}