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:
parent
cafae42d3c
commit
eb3ee7631f
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user