Skip to content

Commit f66f90d

Browse files
committed
key-value item, allow to store any
1 parent 36d2bd1 commit f66f90d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

action.set.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ action:
1313
title: Value
1414
description: Value
1515
default: ""
16+
options:
17+
- name: format
18+
title: Value Format
19+
description: Format to parse the input value
20+
enum: ["string", "yaml"]
21+
default: string

plugin.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,20 @@ func (p *Plugin) DiscoverActions(_ context.Context) ([]*action.Action, error) {
175175
key := KeyValueItem{
176176
Key: input.Arg("key").(string),
177177
}
178-
key.Value, _ = input.Arg("value").(string)
178+
179+
userValue := input.Arg("value").(string)
180+
format := input.Opt("format")
181+
if format == "yaml" && userValue != "" {
182+
yamlValue, err := parseYamlString(userValue)
183+
if err != nil {
184+
return fmt.Errorf("failed to parse YAML: %w", err)
185+
}
186+
187+
key.Value = yamlValue
188+
} else {
189+
key.Value = userValue
190+
}
191+
179192
return saveKey(p.k, key)
180193
}))
181194

yaml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,9 @@ func (s *dataStoreYaml) Save() error {
235235
func (s *dataStoreYaml) Destroy() error {
236236
return s.file.Remove()
237237
}
238+
239+
func parseYamlString(value string) (interface{}, error) {
240+
var yamlValue interface{}
241+
err := yaml.Unmarshal([]byte(value), &yamlValue)
242+
return yamlValue, err
243+
}

0 commit comments

Comments
 (0)