ClientCLIFiles returns the CLI files to generate a command-line client that makes gRPC requests.
(genpkg string, services *ServicesData)
| 12 | // ClientCLIFiles returns the CLI files to generate a command-line client that |
| 13 | // makes gRPC requests. |
| 14 | func ClientCLIFiles(genpkg string, services *ServicesData) []*codegen.File { |
| 15 | if len(services.Root.API.GRPC.Services) == 0 { |
| 16 | return nil |
| 17 | } |
| 18 | var ( |
| 19 | data = make([]*cli.CommandData, 0, len(services.Root.API.GRPC.Services)) |
| 20 | svcs = make([]*expr.GRPCServiceExpr, 0, len(services.Root.API.GRPC.Services)) |
| 21 | ) |
| 22 | for _, svc := range services.Root.API.GRPC.Services { |
| 23 | if len(svc.GRPCEndpoints) == 0 { |
| 24 | continue |
| 25 | } |
| 26 | sd := services.Get(svc.Name()) |
| 27 | command := cli.BuildCommandData(sd.Service) |
| 28 | for _, e := range sd.Endpoints { |
| 29 | flags, buildFunction := buildFlags(e) |
| 30 | subcmd := cli.BuildSubcommandData(sd.Service, e.Method, buildFunction, flags) |
| 31 | command.Subcommands = append(command.Subcommands, subcmd) |
| 32 | } |
| 33 | command.Example = command.Subcommands[0].Example |
| 34 | data = append(data, command) |
| 35 | svcs = append(svcs, svc) |
| 36 | } |
| 37 | files := make([]*codegen.File, 0, len(services.Root.API.Servers)+len(svcs)) |
| 38 | for _, svr := range services.Root.API.Servers { |
| 39 | files = append(files, endpointParser(genpkg, services, svr, data)) |
| 40 | } |
| 41 | for i, svc := range svcs { |
| 42 | files = append(files, payloadBuilders(genpkg, svc, data[i], services)) |
| 43 | } |
| 44 | return files |
| 45 | } |
| 46 | |
| 47 | // endpointParser returns the file that implements the command line parser that |
| 48 | // builds the client endpoint and payload necessary to perform a request. |