MCPcopy Create free account
hub / github.com/containerd/nerdctl / parseChanges

Function parseChanges

pkg/cmd/container/commit.go:81–121  ·  view source on GitHub ↗
(userChanges []string)

Source from the content-addressed store, hash-verified

79}
80
81func parseChanges(userChanges []string) (commit.Changes, error) {
82 const (
83 // XXX: Where can I get a constants for this?
84 commandDirective = "CMD"
85 entrypointDirective = "ENTRYPOINT"
86 )
87 if userChanges == nil {
88 return commit.Changes{}, nil
89 }
90 var changes commit.Changes
91 for _, change := range userChanges {
92 if change == "" {
93 return commit.Changes{}, fmt.Errorf("received an empty value in change flag")
94 }
95 changeFields := strings.Fields(change)
96
97 switch changeFields[0] {
98 case commandDirective:
99 var overrideCMD []string
100 if err := json.Unmarshal([]byte(change[len(changeFields[0]):]), &overrideCMD); err != nil {
101 return commit.Changes{}, fmt.Errorf("malformed json in change flag value %q", change)
102 }
103 if changes.CMD != nil {
104 log.L.Warn("multiple change flags supplied for the CMD directive, overriding with last supplied")
105 }
106 changes.CMD = overrideCMD
107 case entrypointDirective:
108 var overrideEntrypoint []string
109 if err := json.Unmarshal([]byte(change[len(changeFields[0]):]), &overrideEntrypoint); err != nil {
110 return commit.Changes{}, fmt.Errorf("malformed json in change flag value %q", change)
111 }
112 if changes.Entrypoint != nil {
113 log.L.Warnf("multiple change flags supplied for the Entrypoint directive, overriding with last supplied")
114 }
115 changes.Entrypoint = overrideEntrypoint
116 default: // TODO: Support the rest of the change directives
117 return commit.Changes{}, fmt.Errorf("unknown change directive %q", changeFields[0])
118 }
119 }
120 return changes, nil
121}

Callers 1

CommitFunction · 0.85

Calls 1

UnmarshalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…