root.go

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