MCPcopy Create free account
hub / github.com/coder/envbuilder / UnmarshalJSON

Method UnmarshalJSON

devcontainer/script.go:25–66  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

23}
24
25func (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
68func argsFromUntypedSlice(args []any) ([]string, error) {
69 if len(args) == 0 {

Callers

nothing calls this directly

Calls 2

argsFromUntypedSliceFunction · 0.85
JoinMethod · 0.80

Tested by

no test coverage detected