(data []byte)
| 23 | } |
| 24 | |
| 25 | func (s *LifecycleScript) UnmarshalJSON(data []byte) error { |
| 26 | var v any |
| 27 | if err := json.Unmarshal(data, &v); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | |
| 31 | switch v := v.(type) { |
| 32 | case string: |
| 33 | s.shellCommands = map[string]string{ |
| 34 | v: v, |
| 35 | } |
| 36 | case []any: |
| 37 | args, err := argsFromUntypedSlice(v) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | desc := strings.Join(args, " ") |
| 42 | s.nonShellCommands = map[string][]string{ |
| 43 | desc: args, |
| 44 | } |
| 45 | case map[string]any: |
| 46 | for desc, command := range v { |
| 47 | switch command := command.(type) { |
| 48 | case string: |
| 49 | if s.shellCommands == nil { |
| 50 | s.shellCommands = make(map[string]string, 1) |
| 51 | } |
| 52 | s.shellCommands[desc] = command |
| 53 | case []any: |
| 54 | args, err := argsFromUntypedSlice(command) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | if s.nonShellCommands == nil { |
| 59 | s.nonShellCommands = make(map[string][]string, 1) |
| 60 | } |
| 61 | s.nonShellCommands[desc] = args |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func argsFromUntypedSlice(args []any) ([]string, error) { |
| 69 | if len(args) == 0 { |
nothing calls this directly
no test coverage detected