generated from wesen/wesen-go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (43 loc) · 1.21 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
56
package main
import (
"embed"
clay "github.com/go-go-golems/clay/pkg"
cmds2 "github.com/go-go-golems/cliopatra/cmd/cliopatra/cmds"
"github.com/go-go-golems/glazed/pkg/help"
"github.com/spf13/cobra"
)
//go:embed doc/*
var docFS embed.FS
func main() {
helpSystem, rootCmd, err := initRootCmd()
cobra.CheckErr(err)
lsCmd := cmds2.NewLsCommand()
rootCmd.AddCommand(lsCmd)
runCmd := cmds2.NewRunCommand()
rootCmd.AddCommand(runCmd)
renderCmd := cmds2.NewRenderCommand()
rootCmd.AddCommand(renderCmd)
_ = helpSystem
err = rootCmd.Execute()
cobra.CheckErr(err)
}
func initRootCmd() (*help.HelpSystem, *cobra.Command, error) {
helpSystem := help.NewHelpSystem()
err := helpSystem.LoadSectionsFromFS(docFS, ".")
cobra.CheckErr(err)
rootCmd := &cobra.Command{
Use: "cliopatra",
Short: "cliopatra is a tool to run and test CLI applications",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Reinitalize the logger after the config has been loaded
err = clay.InitLogger()
cobra.CheckErr(err)
},
}
helpSystem.SetupCobraRootCommand(rootCmd)
err = clay.InitViper("cliopatra", rootCmd)
cobra.CheckErr(err)
err = clay.InitLogger()
cobra.CheckErr(err)
return helpSystem, rootCmd, nil
}