-
Notifications
You must be signed in to change notification settings - Fork 8
/
root.go
44 lines (38 loc) · 941 Bytes
/
root.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
package main
import (
"io"
"github.com/spf13/cobra"
)
type GlobalOptions struct {
Verbose bool
Insecure bool
Input io.Reader
Output io.Writer
}
type RootCommand struct {
cmd *cobra.Command
opts *GlobalOptions
}
func NewRootCommand(r io.Reader, w io.Writer) *RootCommand {
c := &RootCommand{
cmd: &cobra.Command{
Use: "grpcurl",
Short: "A handy and universal gRPC command line client",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
},
opts: &GlobalOptions{
Input: r,
Output: w,
},
}
c.cmd.PersistentFlags().BoolVarP(&c.opts.Verbose, "verbose", "v", false, "verbose output")
c.cmd.PersistentFlags().BoolVarP(&c.opts.Insecure, "insecure", "k", false, "with insecure")
c.cmd.AddCommand(NewListServicesCommand(c.opts).Command())
c.cmd.AddCommand(NewCallCommand(c.opts).Command())
return c
}
func (c *RootCommand) Command() *cobra.Command {
return c.cmd
}