2018-02-14 22:06:05 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/drone/drone-cli/drone/internal"
|
2019-09-18 22:36:14 +02:00
|
|
|
"github.com/drone/funcmap"
|
|
|
|
"github.com/urfave/cli"
|
2018-02-14 22:06:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var serverInfoCmd = cli.Command{
|
|
|
|
Name: "info",
|
|
|
|
Usage: "show server details",
|
|
|
|
ArgsUsage: "<servername>",
|
|
|
|
Action: serverInfo,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-07-18 23:43:42 +02:00
|
|
|
Name: "format",
|
|
|
|
Usage: "format output",
|
|
|
|
Value: tmplServerInfo,
|
2018-02-14 22:06:05 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-09-18 22:36:14 +02:00
|
|
|
tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n")
|
2018-02-14 22:06:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tmpl.Execute(os.Stdout, server)
|
|
|
|
}
|
|
|
|
|
|
|
|
// template for server information
|
|
|
|
var tmplServerInfo = `Name: {{ .Name }}
|
|
|
|
Address: {{ .Address }}
|
2018-03-09 18:16:32 +01:00
|
|
|
Region: {{ .Region }}
|
|
|
|
Size: {{.Size}}
|
|
|
|
State: {{ .State }}
|
|
|
|
{{ if .Error -}}
|
|
|
|
Error: {{ .Error }}
|
|
|
|
{{ end -}}
|
2018-03-01 20:23:03 +01:00
|
|
|
`
|