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
This commit is contained in:
@ -104,6 +104,27 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
return c.printReplication(printOpts)
|
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 {
|
type printReplicationOpts struct {
|
||||||
replication *api.Replication
|
replication *api.Replication
|
||||||
replications []api.Replication
|
replications []api.Replication
|
||||||
|
@ -98,7 +98,7 @@ func newRemoteDeleteCmd() cli.Command {
|
|||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "remote-id, id",
|
Name: "id, i",
|
||||||
Usage: "ID of the remote connection to be deleted",
|
Usage: "ID of the remote connection to be deleted",
|
||||||
Required: true,
|
Required: true,
|
||||||
Destination: &remoteID,
|
Destination: &remoteID,
|
||||||
@ -172,7 +172,7 @@ func newRemoteUpdateCmd() cli.Command {
|
|||||||
Flags: append(
|
Flags: append(
|
||||||
commonFlags(),
|
commonFlags(),
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "remote-id, id",
|
Name: "id, i",
|
||||||
Usage: "Remote connection ID",
|
Usage: "Remote connection ID",
|
||||||
Required: true,
|
Required: true,
|
||||||
Destination: ¶ms.RemoteID,
|
Destination: ¶ms.RemoteID,
|
||||||
|
@ -93,13 +93,29 @@ func newReplicationCreateCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newReplicationDeleteCmd() cli.Command {
|
func newReplicationDeleteCmd() cli.Command {
|
||||||
|
var replicationID string
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "Delete an existing replication stream",
|
Usage: "Delete an existing replication stream",
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: commonFlags(),
|
Flags: append(
|
||||||
Action: func(ctx *cli.Context) {
|
commonFlags(),
|
||||||
fmt.Println("replication delete command was called")
|
&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)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user