diff --git a/cmd/cloudflared/tunnel/subcommands.go b/cmd/cloudflared/tunnel/subcommands.go index 07740789..5a979dad 100644 --- a/cmd/cloudflared/tunnel/subcommands.go +++ b/cmd/cloudflared/tunnel/subcommands.go @@ -22,6 +22,11 @@ import ( ) var ( + showDeletedFlag = &cli.BoolFlag{ + Name: "show-deleted", + Aliases: []string{"d"}, + Usage: "Include deleted tunnels in the list", + } outputFormatFlag = &cli.StringFlag{ Name: "output", Aliases: []string{"o"}, @@ -137,7 +142,7 @@ func buildListCommand() *cli.Command { Usage: "List existing tunnels", ArgsUsage: " ", 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) - tunnels, err := client.ListTunnels() + allTunnels, err := client.ListTunnels() if err != nil { 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 != "" { return renderOutput(outputFormat, tunnels) } diff --git a/tunnelstore/client.go b/tunnelstore/client.go index 2730cdb1..3f772852 100644 --- a/tunnelstore/client.go +++ b/tunnelstore/client.go @@ -30,6 +30,7 @@ type Tunnel struct { ID string `json:"id"` Name string `json:"name"` CreatedAt time.Time `json:"created_at"` + DeletedAt time.Time `json:"deleted_at"` Connections []Connection `json:"connections"` }