Skip to content

Commit 27b2edf

Browse files
committed
Update main.go
1 parent 572da30 commit 27b2edf

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

main.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import (
1818
type Config struct {
1919
Vars map[string]string `yaml:"vars"`
2020
Parallel bool `yaml:"parallel"`
21+
Usage string `yaml:"usage"` // Add the usage field
2122
Tasks []struct {
2223
Name string `yaml:"name"`
2324
Cmds []string `yaml:"cmds"`
2425
Silent bool `yaml:"silent"`
2526
} `yaml:"modules"`
2627
}
2728

29+
2830
func main() {
2931
var (
3032
taskFile string
@@ -56,7 +58,7 @@ func main() {
5658
/_/ \____/\___ /\____/\___/_/
5759
/____/
5860
59-
- v0.0.3
61+
- v0.0.4
6062
6163
`))
6264

@@ -96,8 +98,14 @@ func main() {
9698

9799
func parseArgs(defaultVars map[string]string) map[string]string {
98100
variables := make(map[string]string)
101+
usageRequested := false
99102

100103
for _, arg := range flag.Args() {
104+
if arg == "usage" || arg == "USAGE" {
105+
usageRequested = true
106+
break
107+
}
108+
101109
parts := strings.SplitN(arg, "=", 2)
102110
if len(parts) == 2 {
103111
if variables == nil {
@@ -107,6 +115,21 @@ func parseArgs(defaultVars map[string]string) map[string]string {
107115
}
108116
}
109117

118+
// Check if "usage" was requested
119+
if usageRequested {
120+
fmt.Println("Usage:")
121+
fmt.Println(defaultVars["USAGE"])
122+
123+
fmt.Println("\nVariables from YAML:")
124+
for key, value := range defaultVars {
125+
if key != "USAGE" {
126+
fmt.Printf("%s: %s\n", key, value)
127+
}
128+
}
129+
130+
os.Exit(0)
131+
}
132+
110133
// Apply default values if not provided by the user
111134
for key, defaultValue := range defaultVars {
112135
if _, exists := variables[key]; !exists {
@@ -118,6 +141,11 @@ func parseArgs(defaultVars map[string]string) map[string]string {
118141
}
119142

120143

144+
145+
146+
147+
148+
121149
func runAllTasks(config Config, variables map[string]string, cyan, magenta, white, yellow, red, green func(a ...interface{}) string) {
122150
var wg sync.WaitGroup
123151
var errorOccurred bool
@@ -212,4 +240,4 @@ func replacePlaceholders(input string, vars map[string]string) string {
212240

213241
func currentTime() string {
214242
return time.Now().Format("2006-01-02 15:04:05")
215-
}
243+
}

0 commit comments

Comments
 (0)