mirror of
https://github.com/rancher/norman.git
synced 2025-09-24 20:48:18 +00:00
k8s vendor to 1.10.5
This commit is contained in:
44
vendor/k8s.io/gengo/args/args.go
generated
vendored
44
vendor/k8s.io/gengo/args/args.go
generated
vendored
@@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -39,13 +40,13 @@ import (
|
||||
// Default returns a defaulted GeneratorArgs. You may change the defaults
|
||||
// before calling AddFlags.
|
||||
func Default() *GeneratorArgs {
|
||||
generatorArgs := &GeneratorArgs{
|
||||
OutputBase: DefaultSourceTree(),
|
||||
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"),
|
||||
GeneratedBuildTag: "ignore_autogenerated",
|
||||
return &GeneratorArgs{
|
||||
OutputBase: DefaultSourceTree(),
|
||||
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"),
|
||||
GeneratedBuildTag: "ignore_autogenerated",
|
||||
GeneratedByCommentTemplate: "// Code generated by GENERATOR_NAME. DO NOT EDIT.",
|
||||
defaultCommandLineFlags: true,
|
||||
}
|
||||
generatorArgs.AddFlags(pflag.CommandLine)
|
||||
return generatorArgs
|
||||
}
|
||||
|
||||
// GeneratorArgs has arguments that are passed to generators.
|
||||
@@ -65,6 +66,11 @@ type GeneratorArgs struct {
|
||||
// Where to get copyright header text.
|
||||
GoHeaderFilePath string
|
||||
|
||||
// If GeneratedByCommentTemplate is set, generate a "Code generated by" comment
|
||||
// below the bloilerplate, of the format defined by this string.
|
||||
// Any instances of "GENERATOR_NAME" will be replaced with the name of the code generator.
|
||||
GeneratedByCommentTemplate string
|
||||
|
||||
// If true, only verify, don't write anything.
|
||||
VerifyOnly bool
|
||||
|
||||
@@ -76,6 +82,15 @@ type GeneratorArgs struct {
|
||||
|
||||
// Any custom arguments go here
|
||||
CustomArgs interface{}
|
||||
|
||||
// Whether to use default command line flags
|
||||
defaultCommandLineFlags bool
|
||||
}
|
||||
|
||||
// WithoutDefaultFlagParsing disables implicit addition of command line flags and parsing.
|
||||
func (g *GeneratorArgs) WithoutDefaultFlagParsing() *GeneratorArgs {
|
||||
g.defaultCommandLineFlags = false
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GeneratorArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
@@ -95,6 +110,16 @@ func (g *GeneratorArgs) LoadGoBoilerplate() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
b = bytes.Replace(b, []byte("YEAR"), []byte(strconv.Itoa(time.Now().Year())), -1)
|
||||
|
||||
if g.GeneratedByCommentTemplate != "" {
|
||||
if len(b) != 0 {
|
||||
b = append(b, byte('\n'))
|
||||
}
|
||||
generatorName := path.Base(os.Args[0])
|
||||
generatedByComment := strings.Replace(g.GeneratedByCommentTemplate, "GENERATOR_NAME", generatorName, -1)
|
||||
s := fmt.Sprintf("%s\n\n", generatedByComment)
|
||||
b = append(b, []byte(s)...)
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
@@ -148,8 +173,11 @@ func DefaultSourceTree() string {
|
||||
// If you don't need any non-default behavior, use as:
|
||||
// args.Default().Execute(...)
|
||||
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error {
|
||||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
pflag.Parse()
|
||||
if g.defaultCommandLineFlags {
|
||||
g.AddFlags(pflag.CommandLine)
|
||||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
pflag.Parse()
|
||||
}
|
||||
|
||||
b, err := g.NewBuilder()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user