summaryrefslogtreecommitdiff
path: root/internal/commands/root.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-08-02 17:25:59 -0600
committerT <t@tjp.lol>2025-08-04 09:34:14 -0600
commit8be5f93f5b2d4b6f438ca84094937a0f7101c59b (patch)
tree3cedb6379818a28179e269477c12ae06dd57ca36 /internal/commands/root.go
Initial commit of punchcard.
Contains working time tracking commands, and the stub of a command to generate reports.
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)
+}