Skip to content

Commit

Permalink
opslevel list tags --type team
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Sep 22, 2023
1 parent be18850 commit ed55b58
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ opslevel create tag --type=Team ID|ALIAS KEY VALUE

var getObjectTagCmd = &cobra.Command{
Use: "tag --type=RESOURCE_TYPE RESOURCE_ID KEY",
Short: "Get value(s) of a tag on an object",
Long: "Get value(s) of a tag on an object",
Short: "Get tags on an object matching key",
Long: "Get tags on an object matching key",
Example: `
opslevel get tag --type=Service ID|ALIAS KEY | jq
`,
Expand Down Expand Up @@ -150,6 +150,38 @@ opslevel get tag --type=Service ID|ALIAS KEY | jq
},
}

var listObjectTagCmd = &cobra.Command{
Use: "tag --type=RESOURCE_TYPE RESOURCE_ID",
Aliases: []string{"tags"},
Short: "Get all tags on an object",
Long: "Get all tags on an object",
Example: `
opslevel list tag --type=Service ID|ALIAS
`,
Args: cobra.ExactArgs(1),
ArgAliases: []string{"RESOURCE_ID"},
Run: func(cmd *cobra.Command, args []string) {
err := validateResourceTypeArg()
cobra.CheckErr(err)

resource := args[0]

var result any
if opslevel.IsID(resource) {
id := opslevel.ID(resource)
result, err = TaggableResourceFetchFunctions[opslevel.TaggableResource(resourceType)](id)
} else {
alias := args[0]
result, err = TaggableResourceFetchAliasFunctions[opslevel.TaggableResource(resourceType)](alias)
}

tags, err := GetTags(result)
cobra.CheckErr(err)

common.PrettyPrint(tags.Nodes)
},
}

var updateTagCmd = &cobra.Command{
Use: "tag TAG_ID KEY VALUE",
Short: "Update a tag",
Expand Down Expand Up @@ -202,6 +234,9 @@ func init() {
getCmd.AddCommand(getObjectTagCmd)
getObjectTagCmd.Flags().StringVar(&resourceType, "type", "", "resource type")

listCmd.AddCommand(listObjectTagCmd)
listObjectTagCmd.Flags().StringVar(&resourceType, "type", "", "resource type")

updateCmd.AddCommand(updateTagCmd)

deleteCmd.AddCommand(deleteTagCmd)
Expand Down

0 comments on commit ed55b58

Please sign in to comment.