@@ -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() {