/
tag.go
72 lines (59 loc) · 1.53 KB
/
tag.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
70
71
72
package commands
import (
"fmt"
"github.com/enfabrica/enkit/astore/client/astore"
"github.com/enfabrica/enkit/lib/kflags"
"github.com/spf13/cobra"
"strings"
)
type TagCommand struct {
*cobra.Command
root *Root
name string
op func([]string) astore.TagModifier
}
func NewTagCommand(root *Root, name string, op func([]string) astore.TagModifier) *TagCommand {
command := &TagCommand{
Command: &cobra.Command{
Use: fmt.Sprintf("%s UID tag [tag]...", name),
Short: fmt.Sprintf("%ss the specified tags", strings.Title(name)),
},
root: root,
name: name,
op: op,
}
command.Command.RunE = command.Run
return command
}
func (uc *TagCommand) Run(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return kflags.NewUsageErrorf("use as 'astore tag %s UID tag [tag]...' - the UID of exactly one artifact, followed by one or more tags", uc.name)
}
uid := args[0]
tags := args[1:]
client, err := uc.root.StoreClient()
if err != nil {
return err
}
arts, err := client.Tag(uid, uc.op(tags))
if err != nil {
return err
}
uc.root.OutputArtifacts(arts)
return nil
}
type Tag struct {
*cobra.Command
}
func NewTag(root *Root) *Tag {
command := &Tag{
Command: &cobra.Command{
Use: "tag",
Short: "Mingles with the tags assigned to artifacts",
},
}
command.Command.AddCommand(NewTagCommand(root, "add", astore.TagAdd).Command)
command.Command.AddCommand(NewTagCommand(root, "del", astore.TagDel).Command)
command.Command.AddCommand(NewTagCommand(root, "set", astore.TagSet).Command)
return command
}