From eb3ee7631fb80eb5d75401004d92c85588774813 Mon Sep 17 00:00:00 2001 From: mcfarlm3 <58636946+mcfarlm3@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:43:03 -0700 Subject: [PATCH] feat: added functionality for replication delete command (#298) * feat: added functionality for replication delete command * refactor: changed naming of remote-id flag to be consistent with other influx commands * refactor: reduced lines of code and improved error message based on code review --- clients/replication/replication.go | 21 +++++++++++++++++++++ cmd/influx/remote.go | 4 ++-- cmd/influx/replication.go | 22 +++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/clients/replication/replication.go b/clients/replication/replication.go index c685164..14ed127 100644 --- a/clients/replication/replication.go +++ b/clients/replication/replication.go @@ -104,6 +104,27 @@ func (c Client) List(ctx context.Context, params *ListParams) error { return c.printReplication(printOpts) } +func (c Client) Delete(ctx context.Context, replicationID string) error { + // get replication stream via ID + connection, err := c.GetReplicationByID(ctx, replicationID).Execute() + if err != nil { + return fmt.Errorf("could not find replication stream with ID %q: %w", replicationID, err) + } + + // send delete request + if err := c.DeleteReplicationByID(ctx, replicationID).Execute(); err != nil { + return fmt.Errorf("failed to delete replication stream %q: %w", replicationID, err) + } + + // print deleted replication stream info + printOpts := printReplicationOpts{ + replication: &connection, + deleted: true, + } + + return c.printReplication(printOpts) +} + type printReplicationOpts struct { replication *api.Replication replications []api.Replication diff --git a/cmd/influx/remote.go b/cmd/influx/remote.go index bc734a5..0eda6a1 100644 --- a/cmd/influx/remote.go +++ b/cmd/influx/remote.go @@ -98,7 +98,7 @@ func newRemoteDeleteCmd() cli.Command { Flags: append( commonFlags(), &cli.StringFlag{ - Name: "remote-id, id", + Name: "id, i", Usage: "ID of the remote connection to be deleted", Required: true, Destination: &remoteID, @@ -172,7 +172,7 @@ func newRemoteUpdateCmd() cli.Command { Flags: append( commonFlags(), &cli.StringFlag{ - Name: "remote-id, id", + Name: "id, i", Usage: "Remote connection ID", Required: true, Destination: ¶ms.RemoteID, diff --git a/cmd/influx/replication.go b/cmd/influx/replication.go index be0cf8f..6e64b99 100644 --- a/cmd/influx/replication.go +++ b/cmd/influx/replication.go @@ -93,13 +93,29 @@ func newReplicationCreateCmd() cli.Command { } func newReplicationDeleteCmd() cli.Command { + var replicationID string return cli.Command{ Name: "delete", Usage: "Delete an existing replication stream", Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs), - Flags: commonFlags(), - Action: func(ctx *cli.Context) { - fmt.Println("replication delete command was called") + Flags: append( + commonFlags(), + &cli.StringFlag{ + Name: "id, i", + Usage: "ID of the replication stream to be deleted", + Required: true, + Destination: &replicationID, + }, + ), + Action: func(ctx *cli.Context) error { + api := getAPI(ctx) + + client := replication.Client{ + CLI: getCLI(ctx), + ReplicationsApi: api.ReplicationsApi, + } + + return client.Delete(getContext(ctx), replicationID) }, } }