-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.go
43 lines (37 loc) · 1.08 KB
/
apply.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package images
import (
"github.com/gomuddle/goba"
"github.com/gomuddle/gobacli/cmd/goba/survey"
"github.com/gomuddle/gobaclient"
"github.com/urfave/cli"
"net/url"
)
// applyCommand returns a command for applying database images to databases.
func applyCommand() cli.Command {
return cli.Command{
Name: "apply",
Flags: []cli.Flag{
cli.StringFlag{Name: "image-name"},
},
Before: survey.RequireMixedFlagsFunc(requiredFlags, "image-name"),
Action: apply(),
}
}
// apply sends a request for applying the image with the given
// parameters to the database with the given type to the server
// at the specified url.
func apply() cli.ActionFunc {
return func(ctx *cli.Context) error {
creds := gobaclient.Credentials{
Username: ctx.Parent().GlobalString("username"),
Password: ctx.Parent().GlobalString("password"),
}
uri, err := url.Parse(ctx.Parent().GlobalString("uri"))
if err != nil {
return err
}
typ := goba.DatabaseType(ctx.Parent().GlobalString("database-type"))
name := ctx.String("image-name")
return gobaclient.ApplyImage(*uri, creds, typ, name)
}
}