blob: 553d0b4f0bb44f45a424e6242d6cd1e18a1ec0e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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())
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)
}
|