| 1 | /* |
| 2 | Copyright 2018 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/ |
| 18 | |
| 19 | import ( |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.21 fmt/" |
| 21 | |
| 22 | "github.com/spf13/pflagscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/" |
| 23 | ) |
| 24 | |
| 25 | type Argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args# struct { |
| 26 | OutputDirscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputDir. string // must be a directory path |
| 27 | OutputPkgscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputPkg. string // must be a Go import-path |
| 28 | OutputFilescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputFile. string |
| 29 | |
| 30 | GoHeaderFilescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#GoHeaderFile. string |
| 31 | |
| 32 | // ReportFilename is added to Args for specifying name of report file used |
| 33 | // by API linter. If specified, API rule violations will be printed to report file. |
| 34 | // Otherwise default value "-" will be used which indicates stdout. |
| 35 | ReportFilenamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#ReportFilename. string |
| 36 | } |
| 37 | |
| 38 | // New returns default arguments for the generator. Returning the arguments instead |
| 39 | // of using default flag parsing allows registering custom arguments afterwards |
| 40 | func Newscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/New().() *Argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args# { |
| 41 | args := &Argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#{} |
| 42 | |
| 43 | // Default value for report filename is "-", which stands for stdout |
| 44 | args.ReportFilenamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#ReportFilename. = "-" |
| 45 | |
| 46 | return args |
| 47 | } |
| 48 | |
| 49 | // AddFlags add the generator flags to the flag set. |
| 50 | func (args *Argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#) AddFlagsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#AddFlags().(fs *pflagscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/.FlagSetscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#) { |
| 51 | fs.StringVarscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#StringVar().(&args.OutputDirscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputDir., "output-dir", "", |
| 52 | "the base directory under which to generate results") |
| 53 | fs.StringVarscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#StringVar().(&args.OutputPkgscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputPkg., "output-pkg", "", |
| 54 | "the base Go import-path under which to generate results") |
| 55 | fs.StringVarscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#StringVar().(&args.OutputFilescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputFile., "output-file", "generated.openapi.go", |
| 56 | "the name of the file to be generated") |
| 57 | fs.StringVarscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#StringVar().(&args.GoHeaderFilescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#GoHeaderFile., "go-header-file", "", |
| 58 | "the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year") |
| 59 | fs.StringVarPscip-go gomod github.com/spf13/pflag v1.0.5 `github.com/spf13/pflag`/FlagSet#StringVarP().(&args.ReportFilenamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#ReportFilename., "report-filename", "r", args.ReportFilenamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#ReportFilename., |
| 60 | "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.") |
| 61 | } |
| 62 | |
| 63 | // Validate checks the given arguments. |
| 64 | func (args *Argsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#) Validatescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#Validate().() error { |
| 65 | if len(args.OutputDirscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputDir.) == 0 { |
| 66 | return fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("--output-dir must be specified") |
| 67 | } |
| 68 | if len(args.OutputPkgscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputPkg.) == 0 { |
| 69 | return fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("--output-pkg must be specified") |
| 70 | } |
| 71 | if len(args.OutputFilescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#OutputFile.) == 0 { |
| 72 | return fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("--output-file must be specified") |
| 73 | } |
| 74 | if len(args.ReportFilenamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/cmd/openapi-gen/args`/Args#ReportFilename.) == 0 { |
| 75 | return fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21 fmt/Errorf().("--report-filename must be specified (use \"-\" for stdout)") |
| 76 | } |
| 77 | return nil |
| 78 | } |