-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
46 lines (43 loc) · 827 Bytes
/
parse.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
package cmd
import (
"errors"
"path/filepath"
"cf-tool/client"
"cf-tool/config"
)
// Parse command
func Parse() (err error) {
cfg := config.Instance
cln := client.Instance
info := Args.Info
source := ""
ext := ""
if cfg.GenAfterParse {
if len(cfg.Template) == 0 {
return errors.New("You have to add at least one code template by `cf config`")
}
path := cfg.Template[cfg.Default].Path
ext = filepath.Ext(path)
if source, err = readTemplateSource(path, cln); err != nil {
return
}
}
work := func() error {
_, paths, err := cln.Parse(info)
if err != nil {
return err
}
if cfg.GenAfterParse {
for _, path := range paths {
gen(source, path, ext)
}
}
return nil
}
if err = work(); err != nil {
if err = loginAgain(cln, err); err == nil {
err = work()
}
}
return
}