add.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package journal
 6
 7import (
 8	"fmt"
 9
10	"github.com/spf13/cobra"
11)
12
13// AddCmd creates a journal entry. Exported for use by the jrnl shortcut.
14var AddCmd = &cobra.Command{
15	Use:   "add [CONTENT]",
16	Short: "Create a journal entry",
17	Long: `Create a journal entry in Lunatask.
18
19Creates an entry for today by default. Use --date to specify another date.
20Use "-" as CONTENT to read from stdin.`,
21	RunE: func(cmd *cobra.Command, args []string) error {
22		date, _ := cmd.Flags().GetString("date")
23		if date == "" {
24			date = "today"
25		}
26
27		// TODO: implement journal entry creation
28		content := ""
29		if len(args) > 0 {
30			content = args[0]
31		}
32		fmt.Fprintf(cmd.OutOrStdout(), "Creating journal entry for %s (not yet implemented)\n", date)
33		if content != "" {
34			fmt.Fprintf(cmd.OutOrStdout(), "Content: %s\n", content)
35		}
36
37		return nil
38	},
39}
40
41func init() {
42	AddCmd.Flags().StringP("date", "d", "", "Entry date (natural language, default: today)")
43	AddCmd.Flags().StringP("name", "n", "", "Entry title (default: weekday name)")
44}