main will generate a file based on the type and template specified. This is to provide an "AllResources" function that is always in sync.
()
| 50 | // This is to provide an "AllResources" function that is always |
| 51 | // in sync. |
| 52 | func 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 | |
| 90 | func generateRBAC(tmpl string) ([]byte, error) { |
| 91 | formatSource := format.Source |
nothing calls this directly
no test coverage detected