summaryrefslogtreecommitdiff
path: root/internal/commands/root.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/commands/root.go')
-rw-r--r--internal/commands/root.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/commands/root.go b/internal/commands/root.go
new file mode 100644
index 0000000..6c400ee
--- /dev/null
+++ b/internal/commands/root.go
@@ -0,0 +1,47 @@
+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())
+
+ 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)
+}