This repository was archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.go
76 lines (67 loc) · 1.58 KB
/
core.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
package main
import (
"net/http"
"os"
"strings"
shellquote "github.com/kballard/go-shellquote"
"github.com/spf13/cast"
)
var (
vars map[string]any
cfg map[string]any
JsonData map[string]string
R Req
Client *http.Client
debug bool
cmdDir string
)
func init() {
JsonData = make(map[string]string)
}
func run(ym map[string]any, commands string) {
if ym[commands] == nil {
ErrPrintf("GMake2: Command not found %v\n", commands)
}
if commands == "vars" || commands == "config" {
ErrPrintf("GMake2: Illegal command group name!")
}
if commands == "end" {
Exit()
}
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
vars[pair[0]] = pair[1]
}
// lines := strings.Split(cast.ToString(ym[commands]), "\n")
lines := ym[commands].([]any)
for is, line := range lines {
if line != nil {
if strings.TrimSpace(cast.ToString(line))[0] == '#' {
continue
}
// line = ResolveVars(vars, line)
cmdStrs, err := shellquote.Split(cast.ToString(line))
BinConfig{CommandLine: is, CommandGroup: commands}.Error(err)
for i, cmdStr := range cmdStrs {
cmdStrs[i] = ResolveVars(vars, cmdStr)
}
bin, args := cmdStrs[0], cmdStrs[1:]
if len(args) == 0 {
ErrPrintf("GMake2: Illegal instruction!\nGMake2: Error Command: %v \n", strings.Join(cmdStrs, " "))
}
bins := BinConfig{
YamlConfig: ym,
YamlData: args,
YamlDataLine: len(args),
YamlDataBin: bin,
CommandGroup: commands,
CommandLine: is,
}
if fc, ok := BinMap[bin]; ok {
fc(bins)
} else {
KW_Default(bin, bins)
}
}
}
}