From ed55b5871876d7039573c0d80137359f52d1f1d2 Mon Sep 17 00:00:00 2001 From: Taimoor Ahmad Date: Fri, 22 Sep 2023 13:56:19 -0400 Subject: [PATCH] opslevel list tags --type team --- src/cmd/tag.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/cmd/tag.go b/src/cmd/tag.go index 4fe1079b..cb1d9259 100644 --- a/src/cmd/tag.go +++ b/src/cmd/tag.go @@ -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 `, @@ -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", @@ -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)