-
Notifications
You must be signed in to change notification settings - Fork 293
/
image.go
48 lines (40 loc) · 1.02 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package value
import (
"fmt"
"github.com/docker/distribution/reference"
"go.starlark.net/starlark"
)
type ImageList []reference.Named
var _ starlark.Unpacker = &ImageList{}
// Unpack an argument that can be expressed as a list or tuple of image references.
func (s *ImageList) Unpack(v starlark.Value) error {
*s = nil
if v == nil {
return nil
}
var iter starlark.Iterator
switch x := v.(type) {
case *starlark.List:
iter = x.Iterate()
case starlark.Tuple:
iter = x.Iterate()
case starlark.NoneType:
return nil
default:
return fmt.Errorf("value should be a List or Tuple of strings, but is of type %s", v.Type())
}
defer iter.Done()
var item starlark.Value
for iter.Next(&item) {
sv, ok := AsString(item)
if !ok {
return fmt.Errorf("value should contain only strings, but element %q was of type %s", item.String(), item.Type())
}
ref, err := reference.ParseNormalizedNamed(sv)
if err != nil {
return fmt.Errorf("must be a valid image reference: %v", err)
}
*s = append(*s, ref)
}
return nil
}