1/* 2Copyright 2016 The Kubernetes Authors. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17// defaulter-gen is a tool for auto-generating Defaulter functions. 18// 19// Given a list of input directories, it will scan for top level types 20// and generate efficient defaulters for an entire object from the sum 21// of the SetDefault_* methods contained in the object tree. 22// 23// Generation is governed by comment tags in the source. Any package may 24// request defaulter generation by including one or more comment tags at 25// the package comment level: 26// 27// // +k8s:defaulter-gen=<field-name-to-flag> 28// 29// which will create defaulters for any type that contains the provided 30// field name (if the type has defaulters). Any type may request explicit 31// defaulting by providing the comment tag: 32// 33// // +k8s:defaulter-gen=true|false 34// 35// An existing defaulter method (`SetDefaults_TYPE`) can provide the 36// comment tag: 37// 38// // +k8s:defaulter-gen=covers 39// 40// to indicate that the defaulter does not or should not call any nested 41// defaulters. 42package main 43 44import ( 45 "k8s.io/gengo/args" 46 "k8s.io/gengo/examples/defaulter-gen/generators" 47 48 "github.com/spf13/pflag" 49 "k8s.io/klog" 50) 51 52func main() { 53 arguments := args.Default() 54 55 // Override defaults. 56 arguments.OutputFileBaseName = "defaulter_generated" 57 58 // Custom args. 59 customArgs := &generators.CustomArgs{ 60 ExtraPeerDirs: []string{}, 61 } 62 pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs, 63 "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.") 64 arguments.CustomArgs = customArgs 65 66 // Run it. 67 if err := arguments.Execute( 68 generators.NameSystems(), 69 generators.DefaultNameSystem(), 70 generators.Packages, 71 ); err != nil { 72 klog.Fatalf("Error: %v", err) 73 } 74 klog.V(2).Info("Completed successfully.") 75} 76