-
Notifications
You must be signed in to change notification settings - Fork 11
/
get_meta_revision.go
66 lines (54 loc) · 1.58 KB
/
get_meta_revision.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
package cmd
import (
"context"
"os"
"strconv"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
"github.com/spf13/cobra"
)
type getRevisionOption struct {
groupName *string
}
var getRevisionOpt getRevisionOption
var getMetaRevisionCmd = &cobra.Command{
Use: "revision [revision_id]",
Short: "Get existing revision given specific conditions",
Args: cobra.MaximumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
if !cmd.Flags().Changed("group") {
getRevisionOpt.groupName = nil
}
},
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
oomStore := mustOpenOomStore(ctx, oomStoreCfg)
defer oomStore.Close()
var groupID *int
if getRevisionOpt.groupName != nil {
group, err := oomStore.GetGroupByName(ctx, *getRevisionOpt.groupName)
if err != nil {
exitf("failed to get feature group name=%s: %+v", *getRevisionOpt.groupName, err)
}
groupID = &group.ID
}
revisions, err := oomStore.ListRevision(ctx, groupID)
if err != nil {
exitf("failed getting revisions, error %+v\n", err)
}
if len(args) > 0 {
if revisions = revisions.Filter(func(r *types.Revision) bool {
return strconv.Itoa(r.ID) == args[0]
}); len(revisions) == 0 {
exitf("revision '%s' not found", args[0])
}
}
if err := serializeMetadata(os.Stdout, revisions, *getMetaOutput, *getMetaWide); err != nil {
exitf("failed printing revisions, error %+v\n", err)
}
},
}
func init() {
getMetaCmd.AddCommand(getMetaRevisionCmd)
flags := getMetaRevisionCmd.Flags()
getRevisionOpt.groupName = flags.StringP("group", "g", "", "feature group")
}