1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-29 21:11:25 +01:00
drone-cli/drone/server/server_info.go
2018-03-01 11:23:03 -08:00

58 lines
1009 B
Go

package server
import (
"fmt"
"os"
"text/template"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var serverInfoCmd = cli.Command{
Name: "info",
Usage: "show server details",
ArgsUsage: "<servername>",
Action: serverInfo,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplServerInfo,
Hidden: true,
},
},
}
func serverInfo(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
server, err := client.Server(name)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, server)
}
// template for server information
var tmplServerInfo = `Name: {{ .Name }}
Address: {{ .Address }}
Region: {{ .Region }}
Size: {{.Size}}
State: {{ .State }}
`