Skip to content

Commit

Permalink
fix(influx): have delete cmd respect the config settings
Browse files Browse the repository at this point in the history
closes: #17289
  • Loading branch information
jsteenb2 committed Jun 2, 2020
1 parent 7c88a79 commit 1a656c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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. [18345](https://github.com/influxdata/influxdb/pull/18345): Have influx delete cmd respect the config

## v2.0.0-beta.11 [2020-05-26]

Expand Down
47 changes: 32 additions & 15 deletions cmd/influx/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,49 @@ import (
"github.com/spf13/cobra"
)

var deleteFlags http.DeleteRequest

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.Long = `Delete points from influxDB, by specify start, end time
and a sql like predicate string.`

opts := flagOpts{
{
DestP: &deleteFlags.OrgID,
DestP: &b.flags.OrgID,
Flag: "org-id",
Desc: "The ID of the organization that owns the bucket",
Persistent: true,
},
{
DestP: &deleteFlags.Org,
DestP: &b.flags.Org,
Flag: "org",
Short: 'o',
Desc: "The name of the organization that owns the bucket",
Persistent: true,
},
{
DestP: &deleteFlags.BucketID,
DestP: &b.flags.BucketID,
Flag: "bucket-id",
Desc: "The ID of the destination bucket",
Persistent: true,
},
{
DestP: &deleteFlags.Bucket,
DestP: &b.flags.Bucket,
Flag: "bucket",
Desc: "The name of destination bucket",
EnvVar: "BUCKET_NAME",
Expand All @@ -47,23 +60,27 @@ func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command {
}
opts.mustRegister(cmd)

cmd.PersistentFlags().StringVar(&deleteFlags.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().StringVarP(&deleteFlags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'")
cmd.PersistentFlags().StringVar(&b.flags.Start, "start", "", "the start 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(&b.flags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'")

return cmd
}

func fluxDeleteF(cmd *cobra.Command, args []string) error {
if deleteFlags.Org == "" && deleteFlags.OrgID == "" {
func (b *cmdDeleteBuilder) fluxDeleteF(cmd *cobra.Command, args []string) error {
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")
}

if deleteFlags.Bucket == "" && deleteFlags.BucketID == "" {
if b.flags.Bucket == "" && b.flags.BucketID == "" {
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")
}

Expand All @@ -74,7 +91,7 @@ func fluxDeleteF(cmd *cobra.Command, args []string) error {
}

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)
}

Expand Down

0 comments on commit 1a656c5

Please sign in to comment.