mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-26 06:07:05 +01:00
Add a filter for server state
This commit is contained in:
parent
cb187f05cb
commit
b4012c3539
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user