Skip to content

Commit 17bd99c

Browse files
committed
more useability tweaking
1 parent ad61173 commit 17bd99c

2 files changed

Lines changed: 40 additions & 28 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Feature
2+
body: Add functionality to `get service tag` to list all the tags
3+
time: 2022-07-07T21:07:18.428703-05:00

src/cmd/service.go

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,46 @@ opslevel create service tag --assign my-service foo bar
7676
},
7777
}
7878

79+
var getServiceCmd = &cobra.Command{
80+
Use: "service ID|ALIAS",
81+
Short: "Get details about a service",
82+
Long: `Get details about a service`,
83+
Args: cobra.ExactArgs(1),
84+
ArgAliases: []string{"ID", "ALIAS"},
85+
Run: func(cmd *cobra.Command, args []string) {
86+
key := args[0]
87+
var result *opslevel.Service
88+
var err error
89+
if common.IsID(key) {
90+
result, err = getClientGQL().GetService(key)
91+
cobra.CheckErr(err)
92+
} else {
93+
result, err = getClientGQL().GetServiceWithAlias(key)
94+
cobra.CheckErr(err)
95+
}
96+
cobra.CheckErr(err)
97+
common.PrettyPrint(result)
98+
},
99+
}
100+
79101
var getServiceTagCmd = &cobra.Command{
80102
Use: "tag ID|ALIAS TAG_KEY",
81103
Short: "Get a service's tag",
82104
Long: `Get a service's' tag
83-
105+
106+
opslevel get service tag my-service | jq 'from_entries'
84107
opslevel get service tag my-service my-tag
85108
`,
86-
Args: cobra.ExactArgs(2),
109+
Args: cobra.MinimumNArgs(1),
87110
ArgAliases: []string{"ID", "ALIAS", "TAG_KEY"},
88111
Run: func(cmd *cobra.Command, args []string) {
89112
serviceKey := args[0]
90-
tagKey := args[1]
113+
singleTag := len(args) == 2
114+
var tagKey string
115+
if singleTag {
116+
tagKey = args[1]
117+
}
118+
91119
var result *opslevel.Service
92120
var err error
93121
if common.IsID(serviceKey) {
@@ -100,35 +128,16 @@ opslevel get service tag my-service my-tag
100128
if result.Id == nil {
101129
cobra.CheckErr(fmt.Errorf("service '%s' not found", serviceKey))
102130
}
131+
output := []opslevel.Tag{}
103132
for _, tag := range result.Tags.Nodes {
104-
if tagKey == tag.Key {
105-
fmt.Println(tag.Value)
106-
return
133+
if singleTag == false || tagKey == tag.Key {
134+
output = append(output, tag)
107135
}
108136
}
109-
cobra.CheckErr(fmt.Errorf("tag with key '%s' not found on service '%s'", tagKey, serviceKey))
110-
},
111-
}
112-
113-
var getServiceCmd = &cobra.Command{
114-
Use: "service ID|ALIAS",
115-
Short: "Get details about a service",
116-
Long: `Get details about a service`,
117-
Args: cobra.ExactArgs(1),
118-
ArgAliases: []string{"ID", "ALIAS"},
119-
Run: func(cmd *cobra.Command, args []string) {
120-
key := args[0]
121-
var result *opslevel.Service
122-
var err error
123-
if common.IsID(key) {
124-
result, err = getClientGQL().GetService(key)
125-
cobra.CheckErr(err)
126-
} else {
127-
result, err = getClientGQL().GetServiceWithAlias(key)
128-
cobra.CheckErr(err)
137+
if len(output) == 0 {
138+
cobra.CheckErr(fmt.Errorf("tag with key '%s' not found on service '%s'", tagKey, serviceKey))
129139
}
130-
cobra.CheckErr(err)
131-
common.PrettyPrint(result)
140+
common.PrettyPrint(output)
132141
},
133142
}
134143

0 commit comments

Comments
 (0)