package cmd import ( "fmt" "os" "git.jnss.me/joakim/opal/internal/engine" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ Use: "opal", Short: "Opal task manager - taskwarrior-inspired CLI task management", Long: `Opal is a powerful command-line task manager inspired by taskwarrior. It supports filtering, tags, priorities, projects, and recurring tasks.`, Run: func(cmd *cobra.Command, args []string) { // Default behavior: show pending tasks if err := listTasks(args); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } }, } func Execute() error { return rootCmd.Execute() } func init() { cobra.OnInitialize(initializeApp) // Add subcommands rootCmd.AddCommand(addCmd) rootCmd.AddCommand(listCmd) rootCmd.AddCommand(doneCmd) rootCmd.AddCommand(modifyCmd) rootCmd.AddCommand(deleteCmd) rootCmd.AddCommand(startCmd) rootCmd.AddCommand(stopCmd) rootCmd.AddCommand(countCmd) rootCmd.AddCommand(projectsCmd) rootCmd.AddCommand(tagsCmd) } func initializeApp() { // Initialize database if err := engine.InitDB(); err != nil { fmt.Fprintf(os.Stderr, "Error initializing database: %v\n", err) os.Exit(1) } // Load config if _, err := engine.LoadConfig(); err != nil { fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err) os.Exit(1) } }