exampleCLIMain returns an example client tool main implementation for the given server expression.
(_ string, root *expr.RootExpr, svr *expr.ServerExpr)
| 24 | // exampleCLIMain returns an example client tool main implementation for the |
| 25 | // given server expression. |
| 26 | func 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, |
no test coverage detected