github.com/jenkins-x/jx-api@v0.0.24/cmd/codegen/app/root.go (about) 1 package app 2 3 import ( 4 "github.com/spf13/cobra" 5 ) 6 7 var ( 8 longHelp = `Generates Go clientsets, OpenAPI spec and API docs for custom resources. 9 10 Custom resources are defined using Go structs. 11 12 Available generators include: 13 14 * openapi - generates OpenAPI specs, required to generate API docs and clients other than Go 15 * docs - generates API docs from the OpenAPI specs 16 * clientset - generates a Go CRUD client directly from custom resources 17 18 ` 19 ) 20 21 // Run executes the Cobra root command. 22 func Run() error { 23 rootCommand := &cobra.Command{ 24 Use: "codegen", 25 Short: "Uses Golang code-generators to generate various application resources and documentation.", 26 Long: longHelp, 27 Run: runHelp, 28 } 29 30 commonOpts := &CommonOptions{ 31 Cmd: rootCommand, 32 } 33 34 genOpts := GenerateOptions{ 35 CommonOptions: commonOpts, 36 } 37 38 rootCommand.PersistentFlags().StringVarP(&commonOpts.GeneratorVersion, "generator-version", "", "master", 39 "Version (really a commit-ish) of the generator tool to use. Allows to pin version using Go modules. Default is master.") 40 41 rootCommand.AddCommand(NewGenerateClientSetCmd(genOpts)) 42 rootCommand.AddCommand(NewCmdCreateClientOpenAPI(genOpts)) 43 rootCommand.AddCommand(NewCreateDocsCmd(genOpts)) 44 45 return rootCommand.Execute() 46 } 47 48 func runHelp(cmd *cobra.Command, _args []string) { 49 cmd.Help() //nolint:errcheck 50 }