-
Notifications
You must be signed in to change notification settings - Fork 1
/
artifact.go
69 lines (57 loc) · 1.68 KB
/
artifact.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cask
import "fmt"
// An ArtifactType represents a known artifact stanza type.
type ArtifactType int
// An Artifact represents the cask artifact stanza itself.
type Artifact struct {
// Type specifies the artifact type.
Type ArtifactType
// Value specifies the artifact value.
Value string
// Target specifies the "target:" value. By default, it's empty string.
Target string
// AllowUntrusted specifies the "allow_untrusted:" value. By default, it's
// false. This should be true only if the Artifact.Type is ArtifactPkg.
AllowUntrusted bool
}
// Different supported artifact types.
const (
ArtifactApp ArtifactType = iota
ArtifactPkg
ArtifactBinary
)
var artifactTypeNames = [...]string{
"app",
"pkg",
"binary",
}
// NewArtifact creates a new Artifact instance and returns its pointer. Requires
// both Artifact.Type and Artifact.Value to be passed as arguments.
func NewArtifact(t ArtifactType, value string) *Artifact {
return &Artifact{t, value, "", false}
}
// String returns the string representation of the ArtifactType.
func (t ArtifactType) String() string {
return artifactTypeNames[t]
}
// String returns the string representation of the Artifact.
func (a Artifact) String() (result string) {
switch a.Type {
case ArtifactApp:
result = fmt.Sprintf("%s, %s", a.Type.String(), a.Value)
if a.Target != "" {
result += fmt.Sprintf(" => %s", a.Target)
}
case ArtifactPkg:
result = fmt.Sprintf("%s, %s", a.Type.String(), a.Value)
if a.AllowUntrusted {
result += ", allow_untrusted: true"
}
case ArtifactBinary:
result = fmt.Sprintf("%s, %s", a.Type.String(), a.Value)
if a.Target != "" {
result += fmt.Sprintf(" => %s", a.Target)
}
}
return result
}