fix(pkger): enforce flag parsing on export all and apply CLI commands

closes: #18850
pull/18871/head
Johnny Steenbergen 2020-07-06 12:46:54 -07:00 committed by Johnny Steenbergen
parent f15fc045fb
commit f804afc6ac
3 changed files with 13 additions and 0 deletions

View File

@ -533,6 +533,16 @@ 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

@ -121,6 +121,7 @@ func (b *cmdTemplateBuilder) cmdApply() *cobra.Command {
func (b *cmdTemplateBuilder) cmdTemplateApply() *cobra.Command {
cmd := b.newCmd("apply", b.applyRunEFn)
enforceFlagValidation(cmd)
cmd.Aliases = []string{"pkg"}
cmd.Short = "Apply a template to manage resources"
cmd.Long = `
@ -473,6 +474,7 @@ 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,6 +44,7 @@ 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`