diff --git a/cmd/task/delete.go b/cmd/task/delete.go index cfb4bd902cd9a0330859ce7b2ba98c9c6c481454..83caed5785745b34feb240f6da989d2c6fba8721 100644 --- a/cmd/task/delete.go +++ b/cmd/task/delete.go @@ -7,6 +7,7 @@ package task import ( "fmt" + "git.secluded.site/lune/internal/client" "git.secluded.site/lune/internal/ui" "git.secluded.site/lune/internal/validate" "github.com/spf13/cobra" @@ -16,27 +17,45 @@ import ( var DeleteCmd = &cobra.Command{ Use: "delete ID", Short: "Delete a task", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - id, err := validate.Reference(args[0]) - if err != nil { - return err - } + Long: `Permanently delete a task from Lunatask. + +Accepts a UUID or lunatask:// deep link. +Prompts for confirmation unless --force is specified.`, + Args: cobra.ExactArgs(1), + RunE: runDelete, +} + +func init() { + DeleteCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt") +} + +func runDelete(cmd *cobra.Command, args []string) error { + id, err := validate.Reference(args[0]) + if err != nil { + return err + } - force, _ := cmd.Flags().GetBool("force") - if !force { - if !ui.Confirm(fmt.Sprintf("Delete task %s?", id)) { - fmt.Fprintln(cmd.OutOrStdout(), "Cancelled") + force, _ := cmd.Flags().GetBool("force") + if !force { + if !ui.Confirm(fmt.Sprintf("Delete task %s?", id)) { + fmt.Fprintln(cmd.OutOrStdout(), "Cancelled") - return nil - } + return nil } + } + + apiClient, err := client.New() + if err != nil { + return err + } + + if _, err := apiClient.DeleteTask(cmd.Context(), id); err != nil { + return err + } - // TODO: implement task deletion - fmt.Fprintf(cmd.OutOrStdout(), "Deleting task %s (not yet implemented)\n", id) + fmt.Fprintln(cmd.OutOrStdout(), ui.Success.Render("Task deleted")) - return nil - }, + return nil } func init() {