-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathargs.go
More file actions
47 lines (41 loc) · 980 Bytes
/
Copy pathargs.go
File metadata and controls
47 lines (41 loc) · 980 Bytes
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
package main
import (
"fmt"
"os"
"strings"
)
type RunConfig struct {
db string
version string
name string
host string
port int
user string
pass string
}
func parseRunArgs(args []string) RunConfig {
cfg := RunConfig{}
parts := strings.SplitN(args[0], "@", 2)
cfg.db = parts[0]
if len(parts) == 2 {
cfg.version = parts[1]
}
for _, arg := range args[1:] {
switch {
case strings.HasPrefix(arg, "--name="):
cfg.name = strings.TrimPrefix(arg, "--name=")
case strings.HasPrefix(arg, "--host="):
cfg.host = strings.TrimPrefix(arg, "--host=")
case strings.HasPrefix(arg, "--port="):
fmt.Sscanf(strings.TrimPrefix(arg, "--port="), "%d", &cfg.port)
case strings.HasPrefix(arg, "--user="):
cfg.user = strings.TrimPrefix(arg, "--user=")
case strings.HasPrefix(arg, "--pass="):
cfg.pass = strings.TrimPrefix(arg, "--pass=")
default:
fmt.Fprintf(os.Stderr, "unknown flag: %s\n", arg)
os.Exit(1)
}
}
return cfg
}