This repository was archived by the owner on Jul 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargument.go
280 lines (208 loc) · 4.5 KB
/
argument.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package main
import (
"errors"
"fmt"
)
type ParsingResult struct {
isForced bool
prog string
path string
config string
author string
brief string
lang Language
std Standard
proj ProjectType
layout ProjectLayout
license License
src string
include string
dist string
test string
example string
}
func NewParsingResult() *ParsingResult {
result := new(ParsingResult)
result.isForced = false
result.prog = "myapp"
result.path = result.prog
result.config = "Makefile"
result.author = "somebody"
result.brief = "something"
result.lang = LANG_C
result.std = STD_C11
result.proj = PROJ_CONSOLE
result.layout = LAYOUT_NESTED
result.license = LICENSE_NONE
result.src = "src"
result.include = "include"
result.dist = "dist"
result.test = "test"
result.example = "example"
return result
}
func (r *ParsingResult) String() string {
out := fmt.Sprintf(`Program name: %s
Project path: %s
Project author: %s
Project brief description: %s
Project language: %s
Project standard: %s
Project type: %s
Project license: %s
Project layout: %s
`, r.Prog(), r.Path(), r.Author(), r.Brief(),
langToString(r.Lang()), stdToString(r.Std()),
projToString(r.Proj()), licenseToRepr(r.License()), layoutToString(r.Layout()),
)
if !r.IsNested() {
return out
}
more := fmt.Sprintf(`Project source directory: %s
Project include directory: %s
Project dist directory: %s
Project test directory: %s
Project example directory: %s
`, r.Src(), r.Include(), r.Dist(), r.Test(), r.Example())
return fmt.Sprintf("%s%s", out, more)
}
func (r *ParsingResult) IsForced() bool {
return r.isForced
}
func (r *ParsingResult) SetForced(isForced bool) {
r.isForced = isForced
}
func (r *ParsingResult) Prog() string {
return r.prog
}
func (r *ParsingResult) SetProg(prog string) error {
if !isValidFileName(prog) {
return errors.New("Invalid program name")
}
r.prog = prog
return nil
}
func (r *ParsingResult) Path() string {
return r.path
}
func (r *ParsingResult) SetPath(path string) error {
if !isValidPath(path) {
return errors.New("Invalid project path")
}
r.path = path
return nil
}
func (r *ParsingResult) Author() string {
return r.author
}
func (r *ParsingResult) SetAuthor(author string) {
if author == "" {
return
}
r.author = author
}
func (r *ParsingResult) Brief() string {
return r.brief
}
func (r *ParsingResult) SetBrief(brief string) {
if brief == "" {
return
}
r.brief = brief
}
func (r *ParsingResult) Config() string {
return r.config
}
func (r *ParsingResult) SetConfig(config string) error {
if !isValidFileName(config) {
return errors.New("Invalid config file name")
}
r.config = config
return nil
}
func (r *ParsingResult) Lang() Language {
return r.lang
}
func (r *ParsingResult) SetLang(lang Language) {
r.lang = lang
}
func (r *ParsingResult) Std() Standard {
return r.std
}
func (r *ParsingResult) SetStd(std Standard) {
r.std = std
}
func (r *ParsingResult) Proj() ProjectType {
return r.proj
}
func (r *ParsingResult) SetProj(proj ProjectType) {
r.proj = proj
}
func (r *ParsingResult) Layout() ProjectLayout {
return r.layout
}
func (r *ParsingResult) SetLayout(layout ProjectLayout) {
r.layout = layout
}
func (r *ParsingResult) IsNested() bool {
return r.layout == LAYOUT_NESTED
}
func (r *ParsingResult) License() License {
return r.license
}
func (r *ParsingResult) SetLicense(license License) {
r.license = license
}
func (r *ParsingResult) Src() string {
return r.src
}
func (r *ParsingResult) SetSrc(src string) error {
if !isValidPath(src) {
return errors.New("Invalid source path")
}
r.src = src
return nil
}
func (r *ParsingResult) Include() string {
return r.include
}
func (r *ParsingResult) SetInclude(include string) error {
if !isValidPath(include) {
return errors.New("Invalid include path")
}
r.include = include
return nil
}
func (r *ParsingResult) Dist() string {
return r.dist
}
func (r *ParsingResult) SetDist(dist string) error {
if !isValidPath(dist) {
return errors.New("Invalid dist path")
}
r.dist = dist
return nil
}
func (r *ParsingResult) Test() string {
return r.test
}
func (r *ParsingResult) SetTest(test string) error {
if !isValidPath(test) {
return errors.New("Invalid test path")
}
r.test = test
return nil
}
func (r *ParsingResult) Example() string {
return r.example
}
func (r *ParsingResult) SetExample(ex string) error {
if !isValidPath(ex) {
return errors.New("Invalid example path")
}
r.example = ex
return nil
}
// Dummy func
func (r *ParsingResult) Create() {
}