Merge pull request #494 from mortent/VerifyOutputFlag

Validate the value of the output flag
This commit is contained in:
Kubernetes Prow Robot 2021-12-09 15:21:05 -08:00 committed by GitHub
commit 9877151bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -109,6 +109,10 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
return err
}
if found := printers.ValidatePrinterType(r.output); !found {
return fmt.Errorf("unknown output type %q", r.output)
}
// TODO: Fix DemandOneDirectory to no longer return FileNameFlags
// since we are no longer using them.
_, err = common.DemandOneDirectory(args)

View File

@ -94,6 +94,11 @@ func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if found := printers.ValidatePrinterType(r.output); !found {
return fmt.Errorf("unknown output type %q", r.output)
}
// Retrieve the inventory object.
reader, err := r.loader.ManifestReader(cmd.InOrStdin(), flagutils.PathFromArgs(args))
if err != nil {

View File

@ -110,6 +110,11 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if found := printers.ValidatePrinterType(r.output); !found {
return fmt.Errorf("unknown output type %q", r.output)
}
objs, err := reader.Read()
if err != nil {
return err

View File

@ -43,3 +43,12 @@ func SupportedPrinters() []string {
func DefaultPrinter() string {
return EventsPrinter
}
func ValidatePrinterType(printerType string) bool {
for _, p := range SupportedPrinters() {
if printerType == p {
return true
}
}
return false
}