Skip to content

Generate command line interfaces to your gRPC services.

License

Notifications You must be signed in to change notification settings

einride/aip-cli-go

Repository files navigation

AIP CLI Go

Generate command line interfaces to your AIP gRPC services.

How to

Step 1: Install the plugin

$ GOBIN=$PWD/build go install go.einride.tech/aip-cli/cmd/protoc-gen-go-aip-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/aip-cli/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/aip-cli/cmd/examplectl

  # The CLI generator optionally generates a root command and a main file
  # to the root of the output module.
  - name: go-aip-cli
    out: cmd/examplectl
    strategy: all
    opt:
      - module=go.einride.tech/aip-cli/cmd/examplectl
      - root=examplectl
      - gcloud_identity_tokens=true

Step 3: Generate the code

$ buf generate \
  --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.