MCPcopy Create free account
hub / github.com/goadesign/goa / ClientCLIFiles

Function ClientCLIFiles

http/codegen/client_cli.go:40–84  ·  view source on GitHub ↗

ClientCLIFiles returns the client HTTP CLI support file.

(genpkg string, data *ServicesData)

Source from the content-addressed store, hash-verified

38
39// ClientCLIFiles returns the client HTTP CLI support file.
40func ClientCLIFiles(genpkg string, data *ServicesData) []*codegen.File {
41 if len(data.Expressions.Services) == 0 {
42 return nil
43 }
44 var (
45 cmds []*commandData
46 svcs []*expr.HTTPServiceExpr
47 )
48 for _, svc := range data.Expressions.Services {
49 sd := data.Get(svc.Name())
50 if len(sd.Endpoints) > 0 {
51 command := &commandData{
52 CommandData: cli.BuildCommandData(sd.Service),
53 NeedDialer: HasWebSocket(sd),
54 }
55
56 for _, e := range sd.Endpoints {
57 sub := buildSubcommandData(sd, e)
58 command.Subcommands = append(command.Subcommands, sub)
59 command.CommandData.Subcommands = append(command.CommandData.Subcommands, sub.SubcommandData)
60 }
61
62 command.Example = command.Subcommands[0].Example
63
64 cmds = append(cmds, command)
65 svcs = append(svcs, svc)
66 }
67 }
68 files := make([]*codegen.File, 0, len(data.Root.API.Servers)*2) // preallocate for CLI files
69 for _, svr := range data.Root.API.Servers {
70 var svrData []*commandData
71 for _, name := range svr.Services {
72 for i, svc := range svcs {
73 if svc.Name() == name {
74 svrData = append(svrData, cmds[i])
75 }
76 }
77 }
78 files = append(files, endpointParser(genpkg, data.Root, svr, svrData, data))
79 }
80 for i, svc := range svcs {
81 files = append(files, payloadBuilders(genpkg, svc, cmds[i].CommandData, data))
82 }
83 return files
84}
85
86func buildSubcommandData(sd *ServiceData, e *EndpointData) *subcommandData {
87 flags, buildFunction := buildFlags(sd, e)

Callers 2

TestClientCLIFilesFunction · 0.70

Calls 7

BuildCommandDataFunction · 0.92
HasWebSocketFunction · 0.85
buildSubcommandDataFunction · 0.85
endpointParserFunction · 0.70
payloadBuildersFunction · 0.70
NameMethod · 0.65
GetMethod · 0.45

Tested by 2

TestClientCLIFilesFunction · 0.56