/
main.go
41 lines (37 loc) · 895 Bytes
/
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
package main
import (
"fmt"
"os"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func main() {
rootCmd := NewRootCmd()
bomcostCmd := NewBomcostCmd()
bommtbfCmd := NewBommtbfCmd()
bommergeCmd := NewBommergeCmd()
versionCmd := NewVersionCmd()
rootCmd.AddCommand(bomcostCmd)
rootCmd.AddCommand(bommtbfCmd)
rootCmd.AddCommand(bommergeCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.SetHelpCommand(helpCommand)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
var helpCommand = &cobra.Command{
Use: "help [command]",
Short: "Help about the command",
RunE: func(c *cobra.Command, args []string) error {
cmd, args, e := c.Root().Find(args)
if cmd == nil || e != nil || len(args) > 0 {
return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
}
helpFunc := cmd.HelpFunc()
helpFunc(cmd, args)
return nil
},
}