delete.go

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