diff --git a/CHANGELOG.md b/CHANGELOG.md index 104a0efce6b..1fd0f4f8515 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ 1. [18392](https://github.com/influxdata/influxdb/pull/18392): Consolidate pkg influx commands under templates. This removes some nesting of the CLI commands as part of that. 1. [18400](https://github.com/influxdata/influxdb/pull/18400): Dashboards maintain sort order after navigating away 1. [18480](https://github.com/influxdata/influxdb/pull/18480): Allows tasks to open in new tabs +1. [18553](https://github.com/influxdata/influxdb/pull/18553): Update usage and soften comparisons for kind matching on 'influx export --resourceType' cmd ### Bug Fixes diff --git a/cmd/influx/pkg.go b/cmd/influx/pkg.go index ce414639aa2..ff9602079df 100644 --- a/cmd/influx/pkg.go +++ b/cmd/influx/pkg.go @@ -315,8 +315,6 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error return err } - opts := []pkger.CreatePkgSetFn{} - resTypes := []struct { kind pkger.Kind idStrs []string @@ -331,6 +329,8 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error {kind: pkger.KindTelegraf, idStrs: strings.Split(b.exportOpts.telegrafs, ",")}, {kind: pkger.KindVariable, idStrs: strings.Split(b.exportOpts.variables, ",")}, } + + var opts []pkger.CreatePkgSetFn for _, rt := range resTypes { newOpt, err := newResourcesToClone(rt.kind, rt.idStrs) if err != nil { @@ -343,9 +343,17 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error return b.exportPkg(cmd.OutOrStdout(), pkgSVC, b.file, opts...) } - kind := pkger.Kind(b.exportOpts.resourceType) - if err := kind.OK(); err != nil { - return errors.New("resource type must be one of bucket|dashboard|label|variable; got: " + b.exportOpts.resourceType) + resType := strings.ToLower(b.exportOpts.resourceType) + resKind := pkger.KindUnknown + for _, k := range pkger.Kinds() { + if strings.ToLower(string(k)) == resType { + resKind = k + break + } + } + + if err := resKind.OK(); err != nil { + return errors.New("resource type is invalid; got: " + b.exportOpts.resourceType) } if stdin, err := b.inStdIn(); err == nil { @@ -355,7 +363,7 @@ func (b *cmdPkgBuilder) pkgExportRunEFn(cmd *cobra.Command, args []string) error } } - resTypeOpt, err := newResourcesToClone(kind, args) + resTypeOpt, err := newResourcesToClone(resKind, args) if err != nil { return err } diff --git a/pkger/models.go b/pkger/models.go index da4914f00e4..d1aef4076a7 100644 --- a/pkger/models.go +++ b/pkger/models.go @@ -31,6 +31,15 @@ const ( KindVariable Kind = "Variable" ) +// Kinds is a list of known pkger kinds. +func Kinds() []Kind { + var out []Kind + for k := range kinds { + out = append(out, k) + } + return out +} + var kinds = map[Kind]bool{ KindBucket: true, KindCheck: true,