TUN-3101: Tunnel list command should only show non-deleted, by default

This commit is contained in:
Adam Chalmers 2020-06-16 17:55:33 -05:00
parent 425554077f
commit b95b289a8c
2 changed files with 19 additions and 2 deletions

View File

@ -22,6 +22,11 @@ import (
) )
var ( var (
showDeletedFlag = &cli.BoolFlag{
Name: "show-deleted",
Aliases: []string{"d"},
Usage: "Include deleted tunnels in the list",
}
outputFormatFlag = &cli.StringFlag{ outputFormatFlag = &cli.StringFlag{
Name: "output", Name: "output",
Aliases: []string{"o"}, Aliases: []string{"o"},
@ -137,7 +142,7 @@ func buildListCommand() *cli.Command {
Usage: "List existing tunnels", Usage: "List existing tunnels",
ArgsUsage: " ", ArgsUsage: " ",
Hidden: hideSubcommands, Hidden: hideSubcommands,
Flags: []cli.Flag{outputFormatFlag}, Flags: []cli.Flag{outputFormatFlag, showDeletedFlag},
} }
} }
@ -157,11 +162,22 @@ func listTunnels(c *cli.Context) error {
} }
client := newTunnelstoreClient(c, cert, logger) client := newTunnelstoreClient(c, cert, logger)
tunnels, err := client.ListTunnels() allTunnels, err := client.ListTunnels()
if err != nil { if err != nil {
return errors.Wrap(err, "Error listing tunnels") return errors.Wrap(err, "Error listing tunnels")
} }
var tunnels []tunnelstore.Tunnel
if c.Bool("show-deleted") {
tunnels = allTunnels
} else {
for _, tunnel := range allTunnels {
if tunnel.DeletedAt.IsZero() {
tunnels = append(tunnels, tunnel)
}
}
}
if outputFormat := c.String(outputFormatFlag.Name); outputFormat != "" { if outputFormat := c.String(outputFormatFlag.Name); outputFormat != "" {
return renderOutput(outputFormat, tunnels) return renderOutput(outputFormat, tunnels)
} }

View File

@ -30,6 +30,7 @@ type Tunnel struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
DeletedAt time.Time `json:"deleted_at"`
Connections []Connection `json:"connections"` Connections []Connection `json:"connections"`
} }