{"id":18114445,"url":"https://github.com/NathanBaulch/protoc-gen-cobra","last_synced_at":"2025-03-29T23:32:16.075Z","repository":{"id":48356207,"uuid":"278353781","full_name":"NathanBaulch/protoc-gen-cobra","owner":"NathanBaulch","description":"Cobra command line tool generator for gRPC clients","archived":false,"fork":true,"pushed_at":"2024-02-15T08:56:38.000Z","size":656,"stargazers_count":45,"open_issues_count":7,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T13:44:57.029Z","etag":null,"topics":["cli","cobra","grpc","grpc-go","protobuf","protocol-buffers"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"tetratelabs/protoc-gen-cobra","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NathanBaulch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-09T12:06:42.000Z","updated_at":"2025-02-07T09:49:26.000Z","dependencies_parsed_at":"2023-02-12T19:45:56.850Z","dependency_job_id":null,"html_url":"https://github.com/NathanBaulch/protoc-gen-cobra","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanBaulch%2Fprotoc-gen-cobra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanBaulch%2Fprotoc-gen-cobra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanBaulch%2Fprotoc-gen-cobra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanBaulch%2Fprotoc-gen-cobra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NathanBaulch","download_url":"https://codeload.github.com/NathanBaulch/protoc-gen-cobra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246258872,"owners_count":20748573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cobra","grpc","grpc-go","protobuf","protocol-buffers"],"created_at":"2024-11-01T03:00:59.134Z","updated_at":"2025-03-29T23:32:11.053Z","avatar_url":"https://github.com/NathanBaulch.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# protoc-gen-cobra\n\nCobra command line tool generator for Go gRPC.\n\n[![GoDoc](https://godoc.org/github.com/NathanBaulch/protoc-gen-cobra?status.svg)](https://godoc.org/github.com/NathanBaulch/protoc-gen-cobra)\n\n### What's this?\n\nA plugin for the [protobuf](https://github.com/google/protobuf) compiler protoc that generates Go code using [cobra](https://github.com/spf13/cobra). It is\ncapable of generating client code for command line tools consistent with your protobuf description.\n\nThis proto definition:\n\n```proto\nservice Bank {\n\trpc Deposit(DepositRequest) returns (DepositReply);\n}\n\nmessage DepositRequest {\n\tstring account = 1;\n\tdouble amount = 2;\n}\n\nmessage DepositReply {\n\tstring account = 1;\n\tdouble balance = 2;\n}\n```\n\nproduces a client that can do:\n\n```\n$ ./example bank deposit --account foobar --amount 10\n$ echo '{\"account\":\"foobar\"}' | ./example bank deposit --amount 10 -f -\n$ set BANK_DEPOSIT_ACCOUNT=foobar; ./example bank deposit --amount 10\n```\n\nIt generates one [cobra.Command](https://godoc.org/github.com/spf13/cobra#Command) per gRPC service (e.g. bank). The service's RPC methods are sub-commands and\nshare the same command line semantics. They take flags, a request file, or stdin for input, and print the response to the terminal in the specified format. The\nclient currently supports basic connectivity settings such as TLS on/off, TLS client authentication and so on.\n\n```\n$ ./example bank deposit -h\nDeposit RPC client\n\nUsage:\n  example bank deposit [flags]\n\nFlags:\n      --account string   account number of recipient\n      --amount float     amount to deposit\n  -h, --help             help for deposit\n\nGlobal Flags:\n      --auth-access-token string   authorization access token\n      --auth-token-type string     authorization token type (default \"Bearer\")\n      --config string              config file (default is $HOME/.example.yaml)\n      --jwt-key string             JWT key\n      --jwt-key-file string        JWT key file\n  -f, --request-file string        client request file; use \"-\" for stdin\n  -i, --request-format string      request format (json, xml, yaml) (default \"json\")\n  -o, --response-format string     response format (json, prettyjson, prettyxml, xml, yaml) (default \"json\")\n  -s, --server-addr string         server address in the form host:port (default \"localhost:8080\")\n      --timeout duration           client connection timeout (default 10s)\n      --tls                        enable TLS\n      --tls-ca-cert-file string    CA certificate file\n      --tls-cert-file string       client certificate file\n      --tls-insecure-skip-verify   INSECURE: skip TLS checks\n      --tls-key-file string        client key file\n      --tls-server-name string     TLS server name override\n```\n\n### Streams\n\ngRPC client and server streams are supported by concatenating multiple requests and responses.\nClient stream requests can be passed from a file or stdin with optional whitespace between each document (typically a new line).\nServer stream responses are printed one per line using the specified response format.\n\nExample client stream:\n\n```\n$ cat req.json\n{\"key\":\"hello\",\"value\":\"world\"}\n{\"key\":\"foo\",\"value\":\"bar\"}\n\n$ ./example cache multiset -f req.json\n```\n\nExample client and server streams:\n\n```\n$ echo '{\"key\":\"hello\"}{\"key\":\"foo\"}' | ./example cache multiget -f -\n{\"value\":\"world\"}\n{\"value\":\"bar\"}\n```\n\nIdle server streams hang until the server closes the stream or a timeout occurs.\n\n### Custom input/output formats\n\nNew input decoders and output encoders can be registered in the host program prior to executing the command.\n\n```go\nclient.RegisterOutputEncoder(\"fmtprint\", func(w io.Writer) iocodec.Encoder {\n\treturn func(v interface{}) error {\n\t\t_, err := fmt.Fprint(w, v)\n\t\treturn err\n\t}\n})\n```\n\nThese formats can then be specified using the `-o` or `--response-format` flags or via a `RESPONSE_FORMAT` environment variable.\n\n```\n$ ./example bank deposit --account foobar --amount 10 -o fmtprint\n$ set RESPONSE_FORMAT=fmtprint; ./example bank deposit --account foobar --amount 10\n```\n\nSee the [yaml format extension](iocodec/yaml/init.go) for a complete example.\n\n### Custom authentication schemes\n\nPre-dial hooks can be registered in the host program to support custom authentication schemes.\n\n```go\nclient.RegisterPreDialer(func(ctx context.Context, opts *[]grpc.DialOption) error {\n\tif creds, ok := ctx.Value(CredsContextKey).(*Creds); ok {\n\t\t*opts = append(*opts, grpc.WithPerRPCCredentials(creds))\n\t}\n\treturn nil\n})\n```\n\nSee the [jwt authentication extension](auth/jwt/init.go) for a complete example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNathanBaulch%2Fprotoc-gen-cobra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNathanBaulch%2Fprotoc-gen-cobra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNathanBaulch%2Fprotoc-gen-cobra/lists"}