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