fix(influx): enforce flag validation

closes: #18629
pull/19055/head
Johnny Steenbergen 2020-07-23 14:11:23 -07:00 committed by Johnny Steenbergen
parent 8678a22ee3
commit fd42c092d0
5 changed files with 7 additions and 19 deletions

View File

@ -1,3 +1,10 @@
## v2.0.0-beta.16 [unreleased]
### Bug Fixes
1. [19043](https://github.com/influxdata/influxdb/pull/19043): Enforce all influx CLI flag args are valid
## v2.0.0-beta.15 [2020-07-23]
### Breaking

View File

@ -102,11 +102,6 @@ func (o genericCLIOpts) newCmd(use string, runE func(*cobra.Command, []string) e
Args: cobra.NoArgs,
Use: use,
RunE: runE,
FParseErrWhitelist: cobra.FParseErrWhitelist{
// allows for unknown flags, parser does not crap the bed
// when providing a flag that doesn't exist/match.
UnknownFlags: true,
},
}
canWrapRunE := runE != nil && o.runEWrapFn != nil
@ -563,16 +558,6 @@ func setViperOptions() {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
}
func enforceFlagValidation(cmd *cobra.Command) {
cmd.FParseErrWhitelist = cobra.FParseErrWhitelist{
// disable unknown flags when short flag can conflict with a long flag.
// An example here is the --filter flag provided as -filter=foo will overwrite
// the -f flag to -f=ilter=foo, which generates a bad filename.
// remedies issue: https://github.com/influxdata/influxdb/issues/18850
UnknownFlags: false,
}
}
func writeJSON(w io.Writer, v interface{}) error {
enc := json.NewEncoder(w)
enc.SetIndent("", "\t")

View File

@ -322,7 +322,6 @@ func (b *cmdTelegrafBuilder) readConfig(file string) (string, error) {
func (b *cmdTelegrafBuilder) newCmd(use string, runE func(*cobra.Command, []string) error) *cobra.Command {
cmd := b.genericCLIOpts.newCmd(use, runE, true)
b.genericCLIOpts.registerPrintOptions(cmd)
enforceFlagValidation(cmd)
return cmd
}

View File

@ -104,7 +104,6 @@ func newCmdPkgerBuilder(svcFn templateSVCsFn, f *globalFlags, opts genericCLIOpt
func (b *cmdTemplateBuilder) cmdApply() *cobra.Command {
cmd := b.newCmd("apply", b.applyRunEFn)
enforceFlagValidation(cmd)
cmd.Short = "Apply a template to manage resources"
cmd.Long = `
The apply command applies InfluxDB template(s). Use the command to create new
@ -456,7 +455,6 @@ func (b *cmdTemplateBuilder) cmdExportAll() *cobra.Command {
and
https://v2.docs.influxdata.com/v2.0/reference/cli/influx/export/all
`
enforceFlagValidation(cmd)
cmd.Flags().StringVarP(&b.file, "file", "f", "", "output file for created template; defaults to std out if no file provided; the extension of provided file (.yml/.json) will dictate encoding")
cmd.Flags().StringArrayVar(&b.filters, "filter", nil, "Filter exported resources by labelName or resourceKind (format: --filter=labelName=example)")

View File

@ -44,7 +44,6 @@ var writeFlags writeFlagsType
func cmdWrite(f *globalFlags, opt genericCLIOpts) *cobra.Command {
cmd := opt.newCmd("write", fluxWriteF, true)
enforceFlagValidation(cmd)
cmd.Args = cobra.MaximumNArgs(1)
cmd.Short = "Write points to InfluxDB"
cmd.Long = `Write data to InfluxDB via stdin, or add an entire file specified with the -f flag`