protoc-gen-go-cli

command module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2022 License: MIT Imports: 4 Imported by: 0

README

protoc-gen-go-cli

Generate command line interfaces to your gRPC services.

How to

Step 1: Install the plugin
$ GOBIN=$PWD/build go install go.einride.tech/protoc-gen-go-cli
Step 2: Configure the code generator

The following example uses a buf generate template to configure the CLI generator.

buf.gen.example.yaml:

version: v1

managed:
  enabled: true
  go_package_prefix:
    default: go.einride.tech/protoc-gen-go-cli/proto/cmd/examplectl
    except:
      - buf.build/googleapis/googleapis

plugins:
  # The CLI generator requires the stubs generated by protoc-gen-go.
  - name: go
    out: cmd/examplectl
    opt: module=go.einride.tech/protoc-gen-go-cli/proto/cmd/examplectl
    path: ./build/protoc-gen-go

  # The CLI generator also requires the stubs generated by protoc-gen-go-grpc.
  - name: go-grpc
    out: cmd/examplectl
    opt: module=go.einride.tech/protoc-gen-go-cli/proto/cmd/examplectl
    path: ./build/protoc-gen-go-grpc

  # The CLI generator optionally generates a root command and a main file
  # to the root of the output module.
  - name: go-cli
    out: cmd/examplectl
    strategy: all
    opt:
      - module=go.einride.tech/protoc-gen-go-cli/proto/cmd/examplectl
      - root=examplectl
      - main=true
      - gcloud_identity_tokens=true
    path: ./build/protoc-gen-go-cli
Step 3: Generate the code
$ buf generate buf.build/einride/aip \
  --template buf.gen.example.yaml \
  --path einride/example/freight
Step 4: Install the CLI
$ go install ./cmd/examplectl
Step 5: Use the CLI
$ examplectl help freight

this api represents a simple freight service

Usage:
  examplectl freight [command]

Available Commands:
  batch-get-sites batch get sites
  create-shipment create a shipment
  create-shipper  create a shipper
  create-site     create a site
  delete-shipment delete a shipment
  delete-shipper  delete a shipper
  delete-site     delete a site
  get-shipment    get a shipment
  get-shipper     get a shipper
  get-site        get a site
  list-shipments  list shipments for a shipper
  list-shippers   list shippers
  list-sites      list sites for a shipper
  update-shipment update a shipment
  update-shipper  update a shipper
  update-site     update a site

Flags:
  -h, --help   help for freight

Global Flags:
      --address string   address to connect to
      --insecure         make insecure client connection (only on localhost)
      --token string     bearer token used by client
  -v, --verbose          print verbose output

Use "examplectl freight [command] --help" for more information about a command.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package cli provides runtime APIs for generated CLIs.
Package cli provides runtime APIs for generated CLIs.
internal
proto
cmd/examplectl
Code generated by protoc-gen-go-cli.
Code generated by protoc-gen-go-cli.
cmd/examplectl/einride/example/freight/v1
Code generated by protoc-gen-go-cli.
Code generated by protoc-gen-go-cli.
Package protoflag provides pflag.Value implementations that convert to protoreflect.Value.
Package protoflag provides pflag.Value implementations that convert to protoreflect.Value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL