-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (47 loc) · 1.14 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/amikos-tech/chromadb-ops/cmd"
"github.com/spf13/cobra"
)
var (
Version = "0.0.0" // Replaced at build time
BuildHash = "0000000" // Replaced at build time
BuildDate = "9999-12-31" // Replace with the actual build date
)
type ChromaOpsCLI struct {
rootCmd *cobra.Command
homeDirProvider cmd.HomeDirProvider
}
type CliOption func(*ChromaOpsCLI) error
func WithHomeDirProvider(provider cmd.HomeDirProvider) CliOption {
return func(c *ChromaOpsCLI) error {
c.homeDirProvider = provider
return nil
}
}
func (c *ChromaOpsCLI) Initialize(options ...CliOption) error {
for _, option := range options {
err := option(c)
if err != nil {
return err
}
}
c.rootCmd = cmd.RootCmd
versionString := fmt.Sprintf("v%s-%s, build date %s\n", Version, BuildHash, BuildDate)
c.rootCmd.SetVersionTemplate(versionString)
err := c.rootCmd.Execute()
if err != nil {
return err
}
return nil
}
func main() {
cli := &ChromaOpsCLI{}
err := cli.Initialize(WithHomeDirProvider(cmd.DefaultHomeDirProvider{}))
if err != nil {
fmt.Printf("Error initializing CLI: %s", err)
os.Exit(1)
}
}