-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathroot.go
65 lines (52 loc) · 1.34 KB
/
root.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"github.com/formancehq/go-libs/v2/bun/bunmigrate"
"github.com/formancehq/go-libs/v2/otlp"
"github.com/formancehq/go-libs/v2/otlp/otlptraces"
"github.com/formancehq/go-libs/v2/service"
"github.com/formancehq/ledger/internal/storage/driver"
"github.com/spf13/cobra"
"github.com/uptrace/bun"
)
const (
ServiceName = "ledger"
)
var (
Version = "develop"
BuildDate = "-"
Commit = "-"
)
func NewRootCommand() *cobra.Command {
root := &cobra.Command{
Use: "ledger",
Short: "ledger",
DisableAutoGenTag: true,
Version: Version,
}
serve := NewServeCommand()
version := NewVersion()
buckets := NewBucket()
root.AddCommand(serve)
root.AddCommand(buckets)
root.AddCommand(version)
root.AddCommand(newMigrationCommand())
root.AddCommand(NewDocsCommand())
service.AddFlags(root.PersistentFlags())
return root
}
func newMigrationCommand() *cobra.Command {
ret := bunmigrate.NewDefaultCommand(func(cmd *cobra.Command, _ []string, db *bun.DB) error {
return withStorageDriver(cmd, func(driver *driver.Driver) error {
if err := driver.Initialize(cmd.Context()); err != nil {
return err
}
return driver.UpgradeAllBuckets(cmd.Context())
})
})
otlp.AddFlags(ret.Flags())
otlptraces.AddFlags(ret.Flags())
return ret
}
func Execute() {
service.Execute(NewRootCommand())
}