mirror of https://github.com/fluxcd/cli-utils.git
Merge pull request #494 from mortent/VerifyOutputFlag
Validate the value of the output flag
This commit is contained in:
commit
9877151bdf
|
|
@ -109,6 +109,10 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
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
|
// TODO: Fix DemandOneDirectory to no longer return FileNameFlags
|
||||||
// since we are no longer using them.
|
// since we are no longer using them.
|
||||||
_, err = common.DemandOneDirectory(args)
|
_, err = common.DemandOneDirectory(args)
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,11 @@ func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if found := printers.ValidatePrinterType(r.output); !found {
|
||||||
|
return fmt.Errorf("unknown output type %q", r.output)
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the inventory object.
|
// Retrieve the inventory object.
|
||||||
reader, err := r.loader.ManifestReader(cmd.InOrStdin(), flagutils.PathFromArgs(args))
|
reader, err := r.loader.ManifestReader(cmd.InOrStdin(), flagutils.PathFromArgs(args))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,11 @@ func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if found := printers.ValidatePrinterType(r.output); !found {
|
||||||
|
return fmt.Errorf("unknown output type %q", r.output)
|
||||||
|
}
|
||||||
|
|
||||||
objs, err := reader.Read()
|
objs, err := reader.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -43,3 +43,12 @@ func SupportedPrinters() []string {
|
||||||
func DefaultPrinter() string {
|
func DefaultPrinter() string {
|
||||||
return EventsPrinter
|
return EventsPrinter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValidatePrinterType(printerType string) bool {
|
||||||
|
for _, p := range SupportedPrinters() {
|
||||||
|
if printerType == p {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue