1
0
Fork 0
mirror of https://github.com/drone/drone-cli.git synced 2024-06-08 23:16:03 +02:00

Add a filter for server state

This commit is contained in:
Thomas Boerger 2019-10-18 10:06:12 +02:00
parent cb187f05cb
commit b4012c3539
No known key found for this signature in database
GPG Key ID: 09745AFF9D63C79B

View File

@ -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,