Skip to content

Commit 5d62fe4

Browse files
authored
Merge pull request #77 from Escape-Technologies/feat/delete-tag-cli
feat: add delete tag functionality
2 parents 16538f8 + 41020ed commit 5d62fe4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pkg/api/escape/tags.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ func CreateTag(ctx context.Context, name string, color string) (*v3.TagDetail, e
3636
return nil, fmt.Errorf("api error: %w", err)
3737
}
3838
return data, nil
39-
}
39+
}
40+
41+
// DeleteTag deletes a tag
42+
func DeleteTag(ctx context.Context, id string) error {
43+
client, err := newAPIV3Client()
44+
if err != nil {
45+
return fmt.Errorf("unable to init client: %w", err)
46+
}
47+
req := client.TagsAPI.DeleteTag(ctx, id)
48+
_, _, err = req.Execute()
49+
if err != nil {
50+
return fmt.Errorf("unable to delete tag: %w", err)
51+
}
52+
return nil
53+
}

pkg/cli/cmd/tags.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,31 @@ Create a new tag with a custom name and color. Use hex color codes without the #
9494
},
9595
}
9696

97+
var tagsDeleteCmd = &cobra.Command{
98+
Use: "delete tag-id",
99+
Aliases: []string{"del", "rm", "remove"},
100+
Args: cobra.ExactArgs(1),
101+
Short: "Delete a tag",
102+
Long: `Delete Tag - Remove tag from organization
103+
104+
Permanently delete a tag from your organization`,
105+
Example: ` # Delete a tag
106+
escape-cli tags delete 00000000-0000-0000-0000-000000000000`,
107+
RunE: func(cmd *cobra.Command, args []string) error {
108+
id := args[0]
109+
err := escape.DeleteTag(cmd.Context(), id)
110+
if err != nil {
111+
return fmt.Errorf("unable to delete tag: %w", err)
112+
}
113+
out.Log("Tag deleted")
114+
return nil
115+
},
116+
}
117+
97118
func init() {
98119
tagsCmd.AddCommand(tagsListCmd)
99120
tagsCmd.AddCommand(tagsCreateCmd)
121+
tagsCmd.AddCommand(tagsDeleteCmd)
100122

101123
tagsCreateCmd.Flags().StringP("name", "n", "", "Name of the tag")
102124
tagsCreateCmd.Flags().StringP("color", "c", "", "Color of the tag")

0 commit comments

Comments
 (0)