fix(influx): have delete cmd respect the config settings

closes: #17289
pull/18357/head
Johnny Steenbergen 2020-06-02 16:06:02 -07:00 committed by Johnny Steenbergen
parent b4f4a11cff
commit d21fce5f6d
2 changed files with 33 additions and 15 deletions

View File

@ -11,6 +11,7 @@
1. [18331](https://github.com/influxdata/influxdb/pull/18331): Support organization name in addition to ID in DBRP operations 1. [18331](https://github.com/influxdata/influxdb/pull/18331): Support organization name in addition to ID in DBRP operations
1. [18335](https://github.com/influxdata/influxdb/pull/18335): Disable failing when providing an unexpected error to influx CLI 1. [18335](https://github.com/influxdata/influxdb/pull/18335): Disable failing when providing an unexpected error to influx CLI
1. [18345](https://github.com/influxdata/influxdb/pull/18345): Have influx delete cmd respect the config
## v2.0.0-beta.11 [2020-05-26] ## v2.0.0-beta.11 [2020-05-26]

View File

@ -9,36 +9,49 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var deleteFlags http.DeleteRequest
func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command { func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command {
cmd := opt.newCmd("delete", fluxDeleteF, true) builder := &cmdDeleteBuilder{
genericCLIOpts: opt,
globalFlags: f,
}
return builder.cmd()
}
type cmdDeleteBuilder struct {
genericCLIOpts
*globalFlags
flags http.DeleteRequest
}
func (b *cmdDeleteBuilder) cmd() *cobra.Command {
cmd := b.newCmd("delete", b.fluxDeleteF, true)
cmd.Short = "Delete points from influxDB" cmd.Short = "Delete points from influxDB"
cmd.Long = `Delete points from influxDB, by specify start, end time cmd.Long = `Delete points from influxDB, by specify start, end time
and a sql like predicate string.` and a sql like predicate string.`
opts := flagOpts{ opts := flagOpts{
{ {
DestP: &deleteFlags.OrgID, DestP: &b.flags.OrgID,
Flag: "org-id", Flag: "org-id",
Desc: "The ID of the organization that owns the bucket", Desc: "The ID of the organization that owns the bucket",
Persistent: true, Persistent: true,
}, },
{ {
DestP: &deleteFlags.Org, DestP: &b.flags.Org,
Flag: "org", Flag: "org",
Short: 'o', Short: 'o',
Desc: "The name of the organization that owns the bucket", Desc: "The name of the organization that owns the bucket",
Persistent: true, Persistent: true,
}, },
{ {
DestP: &deleteFlags.BucketID, DestP: &b.flags.BucketID,
Flag: "bucket-id", Flag: "bucket-id",
Desc: "The ID of the destination bucket", Desc: "The ID of the destination bucket",
Persistent: true, Persistent: true,
}, },
{ {
DestP: &deleteFlags.Bucket, DestP: &b.flags.Bucket,
Flag: "bucket", Flag: "bucket",
Desc: "The name of destination bucket", Desc: "The name of destination bucket",
EnvVar: "BUCKET_NAME", EnvVar: "BUCKET_NAME",
@ -47,23 +60,27 @@ func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command {
} }
opts.mustRegister(cmd) opts.mustRegister(cmd)
cmd.PersistentFlags().StringVar(&deleteFlags.Start, "start", "", "the start time in RFC3339Nano format, exp 2009-01-02T23:00:00Z") cmd.PersistentFlags().StringVar(&b.flags.Start, "start", "", "the start time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVar(&deleteFlags.Stop, "stop", "", "the stop time in RFC3339Nano format, exp 2009-01-02T23:00:00Z") cmd.PersistentFlags().StringVar(&b.flags.Stop, "stop", "", "the stop time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVarP(&deleteFlags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'") cmd.PersistentFlags().StringVarP(&b.flags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'")
return cmd return cmd
} }
func fluxDeleteF(cmd *cobra.Command, args []string) error { func (b *cmdDeleteBuilder) fluxDeleteF(cmd *cobra.Command, args []string) error {
if deleteFlags.Org == "" && deleteFlags.OrgID == "" { org := b.flags.Org
if org == "" {
org = b.globalFlags.Org
}
if org == "" && b.flags.OrgID == "" {
return fmt.Errorf("please specify one of org or org-id") return fmt.Errorf("please specify one of org or org-id")
} }
if deleteFlags.Bucket == "" && deleteFlags.BucketID == "" { if b.flags.Bucket == "" && b.flags.BucketID == "" {
return fmt.Errorf("please specify one of bucket or bucket-id") return fmt.Errorf("please specify one of bucket or bucket-id")
} }
if deleteFlags.Start == "" || deleteFlags.Stop == "" { if b.flags.Start == "" || b.flags.Stop == "" {
return fmt.Errorf("both start and stop are required") return fmt.Errorf("both start and stop are required")
} }
@ -74,7 +91,7 @@ func fluxDeleteF(cmd *cobra.Command, args []string) error {
} }
ctx := signals.WithStandardSignals(context.Background()) ctx := signals.WithStandardSignals(context.Background())
if err := s.DeleteBucketRangePredicate(ctx, deleteFlags); err != nil && err != context.Canceled { if err := s.DeleteBucketRangePredicate(ctx, b.flags); err != nil && err != context.Canceled {
return fmt.Errorf("failed to delete data: %v", err) return fmt.Errorf("failed to delete data: %v", err)
} }