Skip to content

Commit

Permalink
cmd/pool: add sidecar list and cancel commands
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Sep 29, 2021
1 parent e111fac commit 3f8f556
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions cmd/pool/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/hex"
"fmt"
"strconv"

Expand All @@ -23,6 +24,8 @@ var sidecarCommands = []cli.Command{
sidecarPrintTicketCommand,
sidecarRegisterCommand,
sidecarExpectChannelCommand,
sidecarListCommand,
sidecarCancelCommand,
},
},
}
Expand Down Expand Up @@ -291,3 +294,80 @@ func sidecarExpectChannel(ctx *cli.Context) error {

return nil
}

var sidecarListCommand = cli.Command{
Name: "list",
Aliases: []string{"l"},
Usage: "list all sidecar tickets",
Action: sidecarList,
}

func sidecarList(ctx *cli.Context) error {
// Show help if no arguments or flags are provided.
if ctx.NArg() != 0 || ctx.NumFlags() != 0 {
_ = cli.ShowCommandHelp(ctx, "list")
return nil
}

client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.ListSidecars(
context.Background(), &poolrpc.ListSidecarsRequest{},
)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

var sidecarCancelCommand = cli.Command{
Name: "cancel",
Aliases: []string{"c"},
Usage: "cancel the execution of a sidecar ticket identified by " +
"its ID",
ArgsUsage: "ticket_id",
Description: `
Tries to cancel the execution of a sidecar ticket identified by its ID.
If a bid order was created for the ticket already, that order is
cancelled on the server side.`,
Action: sidecarCancel,
}

func sidecarCancel(ctx *cli.Context) error {
// Show help if no arguments or flags are provided.
if ctx.NArg() != 1 || ctx.NumFlags() != 0 {
_ = cli.ShowCommandHelp(ctx, "cancel")
return nil
}

client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

idBytes, err := hex.DecodeString(ctx.Args().First())
if err != nil {
return fmt.Errorf("error decoding ticket ID: %v", err)
}

resp, err := client.CancelSidecar(
context.Background(), &poolrpc.CancelSidecarRequest{
SidecarId: idBytes,
},
)
if err != nil {
return err
}

printRespJSON(resp)

return nil
}

0 comments on commit 3f8f556

Please sign in to comment.