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/go-lunatask"
11 "git.secluded.site/lune/internal/client"
12 "git.secluded.site/lune/internal/ui"
13 "git.secluded.site/lune/internal/validate"
14 "github.com/spf13/cobra"
15)
16
17// DeleteCmd deletes a note. Exported for potential use by shortcuts.
18var DeleteCmd = &cobra.Command{
19 Use: "delete ID",
20 Short: "Delete a note",
21 Long: `Delete a note from Lunatask.
22
23Accepts a UUID or lunatask:// deep link.`,
24 Args: cobra.ExactArgs(1),
25 RunE: runDelete,
26}
27
28func init() {
29 DeleteCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
30}
31
32func runDelete(cmd *cobra.Command, args []string) error {
33 id, err := validate.Reference(args[0])
34 if err != nil {
35 return err
36 }
37
38 force, _ := cmd.Flags().GetBool("force")
39 if !force {
40 if !ui.Confirm(fmt.Sprintf("Delete note %s?", id)) {
41 fmt.Fprintln(cmd.OutOrStdout(), "Cancelled")
42
43 return nil
44 }
45 }
46
47 apiClient, err := client.New()
48 if err != nil {
49 return err
50 }
51
52 note, err := ui.Spin("Deleting note…", func() (*lunatask.Note, error) {
53 return apiClient.DeleteNote(cmd.Context(), id)
54 })
55 if err != nil {
56 return err
57 }
58
59 fmt.Fprintln(cmd.OutOrStdout(), ui.Success.Render("Deleted note: "+note.ID))
60
61 return nil
62}