-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (45 loc) · 1.09 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
package main
import (
"errors"
"fmt"
"github.com/QuangTung97/otelwrap/otelwrap"
"github.com/spf13/cobra"
"os"
)
func main() {
cmd := &cobra.Command{
Use: "otelwrap",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("missing directory and interface list")
}
if args[0] != "." {
return errors.New("only support '.' as directory")
}
out, err := cmd.Flags().GetString("out")
if err != nil {
return err
}
if out == "" {
return errors.New("missing 'out' flag")
}
pkgName, err := cmd.Flags().GetString("pkg")
if err != nil {
return err
}
return otelwrap.RunCommand(otelwrap.CommandArgs{
Dir: args[0],
SrcFileName: os.Getenv("GOFILE"),
InterfaceNames: args[1:],
InAnother: otelwrap.CheckInAnother(out),
PkgName: pkgName,
}, out)
},
}
cmd.Flags().String("out", "", "required, output file name")
cmd.Flags().String("pkg", "", "package name if specified interface is in another package")
err := cmd.Execute()
if err != nil {
fmt.Println("ERROR:", err)
}
}