feat: added functionality for remote delete command (#283)

* feat: added functionality for remote delete command

* chore: pulled recent openapi changes and ran make fmt
This commit is contained in:
mcfarlm3 2021-10-04 10:02:36 -07:00 committed by GitHub
parent d0640ad6c4
commit b7627a33c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

@ -1 +1 @@
Subproject commit d6f9073685dfb58e36f20c2ed351cf872ad31a86
Subproject commit 588064fe68e7dfeebd019695aa805832632cbfb6

View File

@ -101,6 +101,29 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
return c.printRemote(printOpts)
}
func (c Client) Delete(ctx context.Context, remoteID string) error {
connection, err := c.GetRemoteConnectionByID(ctx, remoteID).Execute()
if err != nil {
return fmt.Errorf("failed to delete remote connection %q: %w", remoteID, err)
}
req := c.DeleteRemoteConnectionByID(ctx, remoteID)
// send delete request
err = req.Execute()
if err != nil {
return fmt.Errorf("failed to delete remote connection %q: %w", remoteID, err)
}
// print deleted connection info
printOpts := printRemoteOpts{
remote: &connection,
deleted: true,
}
return c.printRemote(printOpts)
}
type printRemoteOpts struct {
remote *api.RemoteConnection
remotes []api.RemoteConnection

View File

@ -92,13 +92,29 @@ func newRemoteCreateCmd() cli.Command {
}
func newRemoteDeleteCmd() cli.Command {
var remoteID string
return cli.Command{
Name: "delete",
Usage: "Delete an existing remote connection",
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
Flags: commonFlags(),
Action: func(ctx *cli.Context) {
fmt.Println("remote delete command was called")
Flags: append(
commonFlags(),
&cli.StringFlag{
Name: "remote-id, id",
Usage: "ID of the remote connection to be deleted",
Required: true,
Destination: &remoteID,
},
),
Action: func(ctx *cli.Context) error {
api := getAPI(ctx)
client := remote.Client{
CLI: getCLI(ctx),
RemoteConnectionsApi: api.RemoteConnectionsApi,
}
return client.Delete(getContext(ctx), remoteID)
},
}
}