2018-03-01 20:23:03 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-03-01 20:23:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var serverCreateCmd = cli.Command{
|
|
|
|
Name: "create",
|
2019-02-22 00:17:11 +01:00
|
|
|
Usage: "create a new server",
|
2018-03-01 20:23:03 +01:00
|
|
|
Action: serverCreate,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-07-18 23:43:42 +02:00
|
|
|
Name: "format",
|
|
|
|
Usage: "format output",
|
|
|
|
Value: tmplServerCreate,
|
2018-03-01 20:23:03 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func serverCreate(c *cli.Context) error {
|
|
|
|
client, err := internal.NewAutoscaleClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
server, err := client.ServerCreate()
|
|
|
|
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-03-01 20:23:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tmpl.Execute(os.Stdout, server)
|
|
|
|
}
|
|
|
|
|
|
|
|
var tmplServerCreate = `Name: {{ .Name }}
|
|
|
|
State: {{ .State }}
|
|
|
|
`
|