-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_args.go
141 lines (132 loc) · 2.77 KB
/
commands_args.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"fmt"
"strings"
)
type flagOption struct {
force bool
buildimage bool
nobuild bool
dockeronly bool
viewsetting bool
}
func parseFlag(args string) (f flagOption) {
s := strings.Fields(args)
a := []string{}
for _, v := range s {
if strings.Contains(v, "=") {
continue
}
a = append(a, v)
}
for _, v := range a {
if strings.Contains(v, "=") {
continue
}
if strings.Contains(v, "force") {
f.force = true
}
if strings.Contains(v, "nobuild") {
f.nobuild = true
}
if strings.Contains(v, "dockeronly") {
f.dockeronly = true
}
if strings.Contains(v, "viewsetting") {
f.viewsetting = true
}
if strings.Contains(v, "buildimage") {
f.buildimage = true
}
}
return
}
func parseProject(args string) (project, branch string, err error) {
args1 := strings.NewReplacer(" force", " ", " nobuild", " ", " dockeronly",
" ", " viewsetting", " ", " buildimage", " ").Replace(args)
s := strings.Fields(args1)
a := []string{}
for _, v := range s {
if strings.Contains(v, "=") {
continue
}
a = append(a, v)
}
if len(a) == 0 {
err = fmt.Errorf("no project arg provided")
return
}
if len(a) < 2 {
project = a[0]
branch = defaultDevBranch // TODO: using config?
}
if len(a) >= 2 {
project = a[0]
branch = a[1]
// if branch == "force" || branch == "nobuild" {
// branch = "develop"
// }
}
if strings.TrimSpace(project) == "" {
err = fmt.Errorf("no project arg provided")
return
}
return
}
type setOption struct {
buildmode string
configver string
devbranch string
selfrelease string
version string
}
func validateSetting(s setOption) error {
if s.buildmode != "" {
if s.buildmode != "auto" && s.buildmode != "disabled" && s.buildmode != "on" && s.buildmode != "manual" {
return fmt.Errorf("expect auto,disabled,on for imagebuild, but got: %v", s.buildmode)
}
}
if s.selfrelease != "" {
if s.selfrelease != "enabled" && s.selfrelease != "disabled" {
return fmt.Errorf("expect enabled,disabled for selfrelease, but got: %v", s.selfrelease)
}
}
return nil
}
func parseSetting(args string) (f setOption) {
f = setOption{
selfrelease: "enabled",
buildmode: "auto",
devbranch: "master",
configver: "phpv1",
version: "v1.0.0",
}
s := strings.Fields(args)
m := make(map[string]string)
for _, v := range s {
if !strings.Contains(v, "=") {
continue
}
ss := strings.Split(v, "=")
if len(ss) != 2 {
continue
}
m[ss[0]] = ss[1]
}
if m["buildmode"] != "" {
f.buildmode = m["buildmode"]
}
if m["devbranch"] != "" {
f.devbranch = m["devbranch"]
}
if m["configver"] != "" {
f.configver = m["configver"]
}
if m["selfrelease"] != "" {
f.selfrelease = m["selfrelease"]
}
if m["version"] != "" {
f.version = m["version"]
}
return
}