MCPcopy Index your code
hub / github.com/coder/coder / main

Function main

scripts/typegen/main.go:52–88  ·  view source on GitHub ↗

main will generate a file based on the type and template specified. This is to provide an "AllResources" function that is always in sync.

()

Source from the content-addressed store, hash-verified

50// This is to provide an "AllResources" function that is always
51// in sync.
52func main() {
53 flag.Parse()
54
55 if len(flag.Args()) < 1 {
56 usage()
57 os.Exit(1)
58 }
59
60 var (
61 out []byte
62 err error
63 )
64
65 // It did not make sense to have 2 different generators that do essentially
66 // the same thing, but different format for the BE and the sdk.
67 // So the argument switches the go template to use.
68 switch strings.ToLower(flag.Args()[0]) {
69 case "rbac":
70 if len(flag.Args()) < 2 {
71 usage()
72 os.Exit(1)
73 }
74 out, err = generateRBAC(flag.Args()[1])
75 case "countries":
76 out, err = generateCountries()
77 default:
78 _, _ = fmt.Fprintf(os.Stderr, "%q is not a valid type\n", flag.Args()[0])
79 usage()
80 os.Exit(2)
81 }
82
83 if err != nil {
84 log.Fatalf("Generate source: %s", err.Error())
85 }
86
87 _, _ = fmt.Fprint(os.Stdout, string(out))
88}
89
90func generateRBAC(tmpl string) ([]byte, error) {
91 formatSource := format.Source

Callers

nothing calls this directly

Calls 8

generateRBACFunction · 0.85
generateCountriesFunction · 0.85
ArgsMethod · 0.80
ExitMethod · 0.80
usageFunction · 0.70
ParseMethod · 0.65
FatalfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected