diff --git a/drone/server/server_list.go b/drone/server/server_list.go index dea5e34..caccbdd 100644 --- a/drone/server/server_list.go +++ b/drone/server/server_list.go @@ -20,6 +20,10 @@ var serverListCmd = cli.Command{ ArgsUsage: " ", Action: serverList, Flags: []cli.Flag{ + cli.StringFlag{ + Name: "s, state", + Usage: "filter by state", + }, cli.BoolFlag{ Name: "a, all", Usage: "include stopped servers", @@ -49,6 +53,7 @@ func serverList(c *cli.Context) error { if err != nil { return err } + s := c.String("s") a := c.Bool("a") l := c.Bool("l") h := c.BoolT("H") @@ -64,7 +69,7 @@ func serverList(c *cli.Context) error { } if l && h { - printLong(servers, a, h) + printLong(servers, s, a, h) return nil } @@ -77,12 +82,17 @@ func serverList(c *cli.Context) error { if !a && server.State == "stopped" { continue } + + if s != "" && s != server.State { + continue + } + tmpl.Execute(os.Stdout, server) } return nil } -func printLong(servers []*drone.Server, a, h bool) { +func printLong(servers []*drone.Server, s string, a, h bool) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0) if h { fmt.Fprintln(w, "Name\tAddress\tState\tCreated") @@ -91,6 +101,9 @@ func printLong(servers []*drone.Server, a, h bool) { if !a && server.State == "stopped" { continue } + if s != "" && s != server.State { + continue + } fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\n", server.Name, server.Address,