Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ 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",
defaultCommandLineFlags: true,
}
generatorArgs.AddFlags(pflag.CommandLine)
return generatorArgs
}

// GeneratorArgs has arguments that are passed to generators.
Expand Down Expand Up @@ -76,6 +75,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) {
Expand Down Expand Up @@ -148,8 +156,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 {
Expand Down