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	"bufio"
 9	"fmt"
10	"os"
11	"strings"
12
13	"git.secluded.site/lune/internal/ui"
14	"git.secluded.site/lune/internal/validate"
15	"github.com/spf13/cobra"
16)
17
18// DeleteCmd deletes a task. Exported for potential use by shortcuts.
19var DeleteCmd = &cobra.Command{
20	Use:   "delete ID",
21	Short: "Delete a task",
22	Args:  cobra.ExactArgs(1),
23	RunE: func(cmd *cobra.Command, args []string) error {
24		if err := validate.ID(args[0]); err != nil {
25			return err
26		}
27
28		force, _ := cmd.Flags().GetBool("force")
29		if !force {
30			fmt.Fprintf(cmd.OutOrStderr(), "%s Delete task %s? [y/N] ",
31				ui.Warning.Render("Warning:"), args[0])
32
33			reader := bufio.NewReader(os.Stdin)
34			response, _ := reader.ReadString('\n')
35			response = strings.TrimSpace(strings.ToLower(response))
36
37			if response != "y" && response != "yes" {
38				fmt.Fprintln(cmd.OutOrStdout(), "Cancelled")
39
40				return nil
41			}
42		}
43
44		// TODO: implement task deletion
45		fmt.Fprintf(cmd.OutOrStdout(), "Deleting task %s (not yet implemented)\n", args[0])
46
47		return nil
48	},
49}
50
51func init() {
52	DeleteCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
53}