diff --git a/pkg/api/escape/tags.go b/pkg/api/escape/tags.go index 8df9e14..6f5859a 100644 --- a/pkg/api/escape/tags.go +++ b/pkg/api/escape/tags.go @@ -36,4 +36,18 @@ func CreateTag(ctx context.Context, name string, color string) (*v3.TagDetail, e return nil, fmt.Errorf("api error: %w", err) } return data, nil -} \ No newline at end of file +} + +// DeleteTag deletes a tag +func DeleteTag(ctx context.Context, id string) error { + client, err := newAPIV3Client() + if err != nil { + return fmt.Errorf("unable to init client: %w", err) + } + req := client.TagsAPI.DeleteTag(ctx, id) + _, _, err = req.Execute() + if err != nil { + return fmt.Errorf("unable to delete tag: %w", err) + } + return nil +} diff --git a/pkg/cli/cmd/tags.go b/pkg/cli/cmd/tags.go index 44269d3..b312762 100644 --- a/pkg/cli/cmd/tags.go +++ b/pkg/cli/cmd/tags.go @@ -94,9 +94,31 @@ Create a new tag with a custom name and color. Use hex color codes without the # }, } +var tagsDeleteCmd = &cobra.Command{ + Use: "delete tag-id", + Aliases: []string{"del", "rm", "remove"}, + Args: cobra.ExactArgs(1), + Short: "Delete a tag", + Long: `Delete Tag - Remove tag from organization + +Permanently delete a tag from your organization`, + Example: ` # Delete a tag + escape-cli tags delete 00000000-0000-0000-0000-000000000000`, + RunE: func(cmd *cobra.Command, args []string) error { + id := args[0] + err := escape.DeleteTag(cmd.Context(), id) + if err != nil { + return fmt.Errorf("unable to delete tag: %w", err) + } + out.Log("Tag deleted") + return nil + }, +} + func init() { tagsCmd.AddCommand(tagsListCmd) tagsCmd.AddCommand(tagsCreateCmd) + tagsCmd.AddCommand(tagsDeleteCmd) tagsCreateCmd.Flags().StringP("name", "n", "", "Name of the tag") tagsCreateCmd.Flags().StringP("color", "c", "", "Color of the tag")