github.com/jenkins-x/jx/v2@v2.1.155/cmd/codegen/app/root.go (about)

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