This repository has been 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
/
main.go
83 lines (71 loc) · 1.77 KB
/
main.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
package main
import (
"os"
"time"
"github.com/3JoB/ulib/fsutil"
"github.com/spf13/cast"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "GMake2",
Usage: "Lightning-like GMake-like programs.",
Before: CliBeforeFunc,
Flags: CliFlag,
Commands: CliCommands,
Action: CliAction,
}
err := app.Run(os.Args)
checkError(err)
}
func CliBeforeFunc(c *cli.Context) error {
// Read debug information
debug, Tags = c.Bool("debug"), c.String("tag")
return nil
}
func CliAction(c *cli.Context) error {
// Parsing GMakefile
ym := parseConfig(c.String("c"))
// Parse Map
parseMap(ym)
// Parse Tags
if Tags != "" {
parseTags(Tags)
}
// Import Proxy Config
ImportProxy(cfg["proxy"])
commands_args := ""
// Check if the initialization command group exists
if ym["init"] != nil {
run(ym, "init")
}
if c.Args().Len() != 0 {
commands_args = c.Args().First()
} else {
if cast.ToString(cfg["default"]) != "" {
commands_args = cast.ToString(cfg["default"])
} else {
commands_args = "all"
}
}
// Execution command group
run(ym, commands_args)
return nil
}
// Create a GMakefile
func InitFile(c *cli.Context) error {
// If GMakefile exists, make it wait 12 seconds
if fsutil.IsExist(e) {
Println("GMake2: Note! There are already GMakefile.yml files in the directory! Now you still have 12 seconds to prevent GMAKE2 from covering the file!")
time.Sleep(time.Second * 12)
remove(e)
Println("GMake2: File is being covered.")
}
// Then write to the file
checkError(write(e, InitFileContent))
/*if err := ufs.File("GMakefile.yml").SetTrunc().Write(InitFileContent); err != nil {
ErrPrintf("GMake2: Error! %v \n", err.Error())
}*/
Println("GMake2: GMakefile.yml file has been generated in the current directory.")
return nil
}