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/config"
11 "github.com/spf13/cobra"
12)
13
14// AddCmd creates a new note. Exported for potential use by shortcuts.
15var AddCmd = &cobra.Command{
16 Use: "add [NAME]",
17 Short: "Create a new note",
18 Long: `Create a new note in Lunatask.
19
20Use "-" as content flag value to read from stdin.`,
21 RunE: func(cmd *cobra.Command, args []string) error {
22 // TODO: implement note creation
23 name := ""
24 if len(args) > 0 {
25 name = args[0]
26 }
27 fmt.Fprintf(cmd.OutOrStdout(), "Creating note: %s (not yet implemented)\n", name)
28
29 return nil
30 },
31}
32
33func init() {
34 AddCmd.Flags().StringP("notebook", "b", "", "Notebook key (from config)")
35 AddCmd.Flags().StringP("content", "c", "", "Note content (use - for stdin)")
36
37 _ = AddCmd.RegisterFlagCompletionFunc("notebook", completeNotebooks)
38}
39
40// completeNotebooks returns notebook keys from config for shell completion.
41func completeNotebooks(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
42 cfg, err := config.Load()
43 if err != nil {
44 return nil, cobra.ShellCompDirectiveError
45 }
46
47 keys := make([]string, len(cfg.Notebooks))
48 for i, n := range cfg.Notebooks {
49 keys[i] = n.Key
50 }
51
52 return keys, cobra.ShellCompDirectiveNoFileComp
53}