update dependencies (#6267)

Signed-off-by: hongming <coder.scala@gmail.com>
This commit is contained in:
hongming
2024-11-06 10:27:06 +08:00
committed by GitHub
parent faf255a084
commit cfebd96a1f
4263 changed files with 341374 additions and 132036 deletions

View File

@@ -18,59 +18,61 @@ package args
import (
"fmt"
"path/filepath"
"github.com/spf13/pflag"
"k8s.io/gengo/args"
)
// CustomArgs is used by the gengo framework to pass args specific to this generator.
type CustomArgs struct {
// ReportFilename is added to CustomArgs for specifying name of report file used
type Args struct {
OutputDir string // must be a directory path
OutputPkg string // must be a Go import-path
OutputFile string
GoHeaderFile string
// ReportFilename is added to Args for specifying name of report file used
// by API linter. If specified, API rule violations will be printed to report file.
// Otherwise default value "-" will be used which indicates stdout.
ReportFilename string
}
// NewDefaults returns default arguments for the generator. Returning the arguments instead
// New returns default arguments for the generator. Returning the arguments instead
// of using default flag parsing allows registering custom arguments afterwards
func NewDefaults() (*args.GeneratorArgs, *CustomArgs) {
// Default() sets a couple of flag default values for example the boilerplate.
// WithoutDefaultFlagParsing() disables implicit addition of command line flags and parsing,
// which allows registering custom arguments afterwards
genericArgs := args.Default().WithoutDefaultFlagParsing()
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), "k8s.io/kube-openapi/boilerplate/boilerplate.go.txt")
customArgs := &CustomArgs{}
genericArgs.CustomArgs = customArgs
func New() *Args {
args := &Args{}
// Default value for report filename is "-", which stands for stdout
customArgs.ReportFilename = "-"
// Default value for output file base name
genericArgs.OutputFileBaseName = "openapi_generated"
args.ReportFilename = "-"
return genericArgs, customArgs
return args
}
// AddFlags add the generator flags to the flag set.
func (c *CustomArgs) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&c.ReportFilename, "report-filename", "r", c.ReportFilename, "Name of report file used by API linter to print API violations. Default \"-\" stands for standard output. NOTE that if valid filename other than \"-\" is specified, API linter won't return error on detected API violations. This allows further check of existing API violations without stopping the OpenAPI generation toolchain.")
func (args *Args) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&args.OutputDir, "output-dir", "",
"the base directory under which to generate results")
fs.StringVar(&args.OutputPkg, "output-pkg", "",
"the base Go import-path under which to generate results")
fs.StringVar(&args.OutputFile, "output-file", "generated.openapi.go",
"the name of the file to be generated")
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
fs.StringVarP(&args.ReportFilename, "report-filename", "r", args.ReportFilename,
"Name of report file used by API linter to print API violations. Default \"-\" stands for standard output. NOTE that if valid filename other than \"-\" is specified, API linter won't return error on detected API violations. This allows further check of existing API violations without stopping the OpenAPI generation toolchain.")
}
// Validate checks the given arguments.
func Validate(genericArgs *args.GeneratorArgs) error {
c, ok := genericArgs.CustomArgs.(*CustomArgs)
if !ok {
return fmt.Errorf("input arguments don't contain valid custom arguments")
func (args *Args) Validate() error {
if len(args.OutputDir) == 0 {
return fmt.Errorf("--output-dir must be specified")
}
if len(c.ReportFilename) == 0 {
return fmt.Errorf("report filename cannot be empty. specify a valid filename or use \"-\" for stdout")
if len(args.OutputPkg) == 0 {
return fmt.Errorf("--output-pkg must be specified")
}
if len(genericArgs.OutputFileBaseName) == 0 {
return fmt.Errorf("output file base name cannot be empty")
if len(args.OutputFile) == 0 {
return fmt.Errorf("--output-file must be specified")
}
if len(genericArgs.OutputPackagePath) == 0 {
return fmt.Errorf("output package cannot be empty")
if len(args.ReportFilename) == 0 {
return fmt.Errorf("--report-filename must be specified (use \"-\" for stdout)")
}
return nil
}

View File

@@ -24,33 +24,38 @@ import (
"flag"
"log"
generatorargs "k8s.io/kube-openapi/cmd/openapi-gen/args"
"k8s.io/kube-openapi/pkg/generators"
"github.com/spf13/pflag"
"k8s.io/gengo/v2"
"k8s.io/gengo/v2/generator"
"k8s.io/klog/v2"
"k8s.io/kube-openapi/cmd/openapi-gen/args"
"k8s.io/kube-openapi/pkg/generators"
)
func main() {
klog.InitFlags(nil)
genericArgs, customArgs := generatorargs.NewDefaults()
args := args.New()
genericArgs.AddFlags(pflag.CommandLine)
customArgs.AddFlags(pflag.CommandLine)
args.AddFlags(pflag.CommandLine)
flag.Set("logtostderr", "true")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
if err := generatorargs.Validate(genericArgs); err != nil {
if err := args.Validate(); err != nil {
log.Fatalf("Arguments validation error: %v", err)
}
myTargets := func(context *generator.Context) []generator.Target {
return generators.GetTargets(context, args)
}
// Generates the code for the OpenAPIDefinitions.
if err := genericArgs.Execute(
if err := gengo.Execute(
generators.NameSystems(),
generators.DefaultNameSystem(),
generators.Packages,
myTargets,
gengo.StdBuildTag,
pflag.Args(),
); err != nil {
log.Fatalf("OpenAPI code generation error: %v", err)
}