mirror of https://github.com/fluxcd/cli-utils.git
Validate the value of the output flag
This commit is contained in:
parent
5b83428a27
commit
9caaf2a225
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue