1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package cmd provides the lune CLI commands.
6package cmd
7
8import (
9 "context"
10 "os"
11
12 "git.secluded.site/lune/cmd/area"
13 "git.secluded.site/lune/cmd/goal"
14 "git.secluded.site/lune/cmd/habit"
15 initcmd "git.secluded.site/lune/cmd/init"
16 "git.secluded.site/lune/cmd/journal"
17 "git.secluded.site/lune/cmd/mcp"
18 "git.secluded.site/lune/cmd/note"
19 "git.secluded.site/lune/cmd/person"
20 "git.secluded.site/lune/cmd/task"
21 "git.secluded.site/lune/internal/config"
22 "git.secluded.site/lune/internal/ui"
23 "github.com/charmbracelet/fang"
24 "github.com/spf13/cobra"
25)
26
27var (
28 version = "dev"
29 commit = "none"
30)
31
32var rootCmd = &cobra.Command{
33 Use: "lune",
34 Short: "A delightful CLI for Lunatask",
35 Long: `lune is a command-line interface for Lunatask, the encrypted
36all-in-one productivity app for tasks, habits, journaling, and more.
37
38Run 'lune init' to configure your access token and get started.`,
39 SilenceUsage: true,
40 SilenceErrors: true,
41 PersistentPreRun: func(_ *cobra.Command, _ []string) {
42 cfg, err := config.Load()
43 if err != nil {
44 return
45 }
46
47 switch cfg.UI.Color {
48 case "always":
49 ui.SetColorMode(ui.ColorAlways)
50 case "never":
51 ui.SetColorMode(ui.ColorNever)
52 default:
53 ui.SetColorMode(ui.ColorAuto)
54 }
55 },
56}
57
58func init() {
59 rootCmd.AddGroup(&cobra.Group{ID: "resources", Title: "Resources"})
60 rootCmd.AddGroup(&cobra.Group{ID: "shortcuts", Title: "Shortcuts"})
61
62 rootCmd.AddCommand(initcmd.Cmd)
63 rootCmd.AddCommand(pingCmd)
64 rootCmd.AddCommand(mcp.Cmd)
65
66 rootCmd.AddCommand(area.Cmd)
67 rootCmd.AddCommand(goal.Cmd)
68 rootCmd.AddCommand(task.Cmd)
69 rootCmd.AddCommand(note.Cmd)
70 rootCmd.AddCommand(person.Cmd)
71 rootCmd.AddCommand(journal.Cmd)
72 rootCmd.AddCommand(habit.Cmd)
73
74 rootCmd.AddCommand(addCmd)
75 rootCmd.AddCommand(doneCmd)
76 rootCmd.AddCommand(jrnlCmd)
77}
78
79// Execute runs the root command with Fang styling.
80func Execute(ctx context.Context, v string) error {
81 version = v
82
83 return fang.Execute(
84 ctx,
85 rootCmd,
86 fang.WithVersion(version),
87 fang.WithCommit(commit),
88 fang.WithNotifySignal(os.Interrupt),
89 )
90}