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

Function exampleCLIMain

codegen/example/example_client.go:26–105  ·  view source on GitHub ↗

exampleCLIMain returns an example client tool main implementation for the given server expression.

(_ string, root *expr.RootExpr, svr *expr.ServerExpr)

Source from the content-addressed store, hash-verified

24// exampleCLIMain returns an example client tool main implementation for the
25// given server expression.
26func exampleCLIMain(_ string, root *expr.RootExpr, svr *expr.ServerExpr) *codegen.File {
27 svrdata := Servers.Get(svr, root)
28
29 // Skip CLI generation for servers with no transports (e.g., agent-only services)
30 if svrdata.DefaultTransport() == nil {
31 return nil
32 }
33
34 path := filepath.Join("cmd", svrdata.Dir+"-cli", "main.go")
35 if _, err := os.Stat(path); !os.IsNotExist(err) {
36 return nil // file already exists, skip it.
37 }
38 specs := []*codegen.ImportSpec{
39 {Path: "context"},
40 {Path: "encoding/json"},
41 {Path: "errors"},
42 {Path: "flag"},
43 {Path: "fmt"},
44 {Path: "net/url"},
45 {Path: "os"},
46 {Path: "sort"},
47 {Path: "slices"},
48 {Path: "strings"},
49 codegen.GoaImport(""),
50 }
51 sections := []*codegen.SectionTemplate{
52 codegen.Header("", "main", specs),
53 {
54 Name: "cli-main-start",
55 Source: exampleTemplates.Read(clientStartT),
56 Data: map[string]any{
57 "Server": svrdata,
58 "HasJSONRPC": hasJSONRPC(root, svr),
59 "HasHTTP": hasHTTP(root, svr),
60 },
61 FuncMap: map[string]any{
62 "join": strings.Join,
63 },
64 }, {
65 Name: "cli-main-var-init",
66 Source: exampleTemplates.Read(clientVarInitT),
67 Data: map[string]any{
68 "Server": svrdata,
69 },
70 FuncMap: map[string]any{
71 "join": strings.Join,
72 },
73 }, {
74 Name: "cli-main-endpoint-init",
75 Source: exampleTemplates.Read(clientEndpointInitT),
76 Data: map[string]any{
77 "Server": svrdata,
78 "Root": root,
79 "HasJSONRPC": hasJSONRPC(root, svr),
80 "HasHTTP": hasHTTP(root, svr),
81 },
82 FuncMap: map[string]any{
83 "join": strings.Join,

Callers 1

CLIFilesFunction · 0.85

Calls 7

GoaImportFunction · 0.92
HeaderFunction · 0.92
hasJSONRPCFunction · 0.85
hasHTTPFunction · 0.85
DefaultTransportMethod · 0.80
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected