Skip to content

Latest commit

 

History

History
112 lines (81 loc) · 3.51 KB

README.md

File metadata and controls

112 lines (81 loc) · 3.51 KB

grpctl

Status GitHub Issues GitHub Pull Requests License

A golang package for easily creating custom cli tools from FileDescriptors, or through the gRPC reflection API.

📖 Table of contents

🪞 Reflection cli mode

To be used like grpcurl against reflection APIs but with tab completion.

grpctl

📥 Install

go get github.com/joshcarp/grpctl/cmd/grpctl
grpctl --help
  -a, --address string       Address in form 'host:port'
      --config string        Config file (default is $HOME/.grpctl.yaml)
  -H, --header stringArray   Header in form 'key: value'
  -h, --help                 help for grpctl
  -p, --plaintext            Dial grpc.WithInsecure

🗄️ File descriptor mode

To easily create a cli tool for your grpc APIs using the code generated protoreflect.FileDescriptor To view all options that can be used, see opts.go.

examplectl

📥 Install

func main() {
	cmd := &cobra.Command{
		Use:   "billingctl",
		Short: "an example cli tool for the gcp billing api",
	}
	err := grpctl.BuildCommand(cmd,
		grpctl.WithArgs(os.Args),
		grpctl.WithFileDescriptors(
			billing.File_google_cloud_billing_v1_cloud_billing_proto,
			billing.File_google_cloud_billing_v1_cloud_catalog_proto,
		),
	)
	if err != nil {
		log.Print(err)
	}
	if err := grpctl.RunCommand(cmd, context.Background()); err != nil {
		log.Print(err)
	}
}

🤖 Autocompletion

run grpctl completion --help and do what it says

🏳️‍🌈 Flags

  • --address and --plaintext
grpctl --address=<host:port> --plaintext=<true/false>
  • it is important that the = is used with flags, otherwise the value will be interpreted as a command which does not exist.

  • --header

grpctl --address=<host:port> --plaintext=<true/false> -H="Foo:Bar" -H="Bar: Foo"
  • Any white spaces at the start of the value will be stripped

🧠 Design

Design documents (more like a stream of consciousness) can be found in ./design.

🔧 Contributing

This project is still in an alpha state, any contributions are welcome see CONTRIBUTING.md.

There is also a slack channel on gophers slack: #grpctl

🖋️ License

See LICENSE for more details.

🎉 Acknowledgements

  • @dancantos and I were talking about protoc-gen-cobra when dan came up with the idea of using the proto descriptors to genreate cobra commands on the fly.