package commands import ( "context" "database/sql" punchctx "punchcard/internal/context" "punchcard/internal/database" "github.com/spf13/cobra" ) func NewRootCmd() *cobra.Command { cmd := &cobra.Command{ Use: "punch", Short: "A simple time tracking CLI tool", Long: "Punchcard helps you track your work hours and generate professional invoices and timesheets.", RunE: NewStatusCmd().RunE, // Default to status command when no subcommand is provided } cmd.AddCommand(NewAddCmd()) cmd.AddCommand(NewInCmd()) cmd.AddCommand(NewOutCmd()) cmd.AddCommand(NewStatusCmd()) cmd.AddCommand(NewImportCmd()) cmd.AddCommand(NewReportCmd()) cmd.AddCommand(NewSetCmd()) cmd.AddCommand(NewTUICmd()) return cmd } func Execute() error { // Get database connection q, err := database.GetDB() if err != nil { return err } defer func() { if db, ok := q.DBTX().(*sql.DB); ok { _ = db.Close() } }() // Create context with database ctx := punchctx.WithDB(context.Background(), q) return NewRootCmd().ExecuteContext(ctx) }