-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (64 loc) · 1.48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/hfaulds/wrappergen/cmd"
)
//go:generate gen tracing -interface=Client
//go:generate gen timing -interface=Client
//go:generate gen constructor -interface=Client -struct=client
var (
rootFlags = &cmd.RootFlags{}
rootCmd = &cobra.Command{
Use: "gen",
Short: "",
Args: cobra.NoArgs,
}
tracingFlags = &cmd.TracingFlags{}
tracingCmd = &cobra.Command{
Use: "tracing",
Short: "",
Args: cobra.NoArgs,
Run: runCommand(func() error {
return cmd.Tracing(rootFlags, tracingFlags)
}),
}
timingFlags = &cmd.TimingFlags{}
timingCmd = &cobra.Command{
Use: "timing",
Short: "",
Args: cobra.NoArgs,
Run: runCommand(func() error {
return cmd.Timing(rootFlags, timingFlags)
}),
}
constructorFlags = &cmd.ConstructorFlags{}
constructorCmd = &cobra.Command{
Use: "constructor",
Short: "",
Args: cobra.NoArgs,
Run: runCommand(func() error {
return cmd.Constructor(rootFlags, constructorFlags)
}),
}
)
func runCommand(fn func() error) func(*cobra.Command, []string) {
return func(cmd *cobra.Command, args []string) {
err := fn()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
}
func main() {
rootFlags.Init(rootCmd)
rootCmd.AddCommand(tracingCmd)
tracingFlags.Init(tracingCmd)
rootCmd.AddCommand(timingCmd)
timingFlags.Init(timingCmd)
rootCmd.AddCommand(constructorCmd)
constructorFlags.Init(constructorCmd)
rootCmd.Execute()
}