-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
53 lines (42 loc) · 1.19 KB
/
utils.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
44
45
46
47
48
49
50
51
52
53
package cmd
import (
"fmt"
"github.com/urfave/cli"
"github.com/vitanovs/versioner/client"
)
func loadClientConfig(ctx *cli.Context) (*client.Config, error) {
cmdName := ctx.Command.FullName()
endpoint := ctx.GlobalString("endpoint")
if endpoint == "" {
return nil, fmt.Errorf("No endpoint specified. See '%s --help'", cmdName)
}
port := ctx.GlobalInt("port")
if port == 0 {
return nil, fmt.Errorf("No port specified. See '%s --help'", cmdName)
}
database := ctx.GlobalString("database")
if database == "" {
return nil, fmt.Errorf("No database specified. See '%s --help'", cmdName)
}
username := ctx.GlobalString("username")
if username == "" {
return nil, fmt.Errorf("No username specified. See '%s --help'", cmdName)
}
password := ctx.GlobalString("password")
if password == "" {
return nil, fmt.Errorf("No password specified. See '%s --help'", cmdName)
}
sslMode := ctx.GlobalString("sslmode")
if sslMode == "" {
return nil, fmt.Errorf("No SSL mode specified. See '%s --help'", cmdName)
}
config := client.Config{
Endpoint: endpoint,
Port: port,
Database: database,
Username: username,
Password: password,
SslMode: sslMode,
}
return &config, nil
}