delete.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package task
 6
 7import (
 8	"fmt"
 9
10	"git.secluded.site/lune/internal/ui"
11	"git.secluded.site/lune/internal/validate"
12	"github.com/spf13/cobra"
13)
14
15// DeleteCmd deletes a task. Exported for potential use by shortcuts.
16var DeleteCmd = &cobra.Command{
17	Use:   "delete ID",
18	Short: "Delete a task",
19	Args:  cobra.ExactArgs(1),
20	RunE: func(cmd *cobra.Command, args []string) error {
21		if err := validate.ID(args[0]); err != nil {
22			return err
23		}
24
25		force, _ := cmd.Flags().GetBool("force")
26		if !force {
27			if !ui.Confirm(fmt.Sprintf("Delete task %s?", args[0])) {
28				fmt.Fprintln(cmd.OutOrStdout(), "Cancelled")
29
30				return nil
31			}
32		}
33
34		// TODO: implement task deletion
35		fmt.Fprintf(cmd.OutOrStdout(), "Deleting task %s (not yet implemented)\n", args[0])
36
37		return nil
38	},
39}
40
41func init() {
42	DeleteCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
43}