-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
125 lines (106 loc) · 2.54 KB
/
Copy pathmain.go
File metadata and controls
125 lines (106 loc) · 2.54 KB
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
package main
import (
"embed"
"fmt"
"io"
"os"
"strings"
"github.com/TrueBlocks/goMaker/v6/types"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/logger"
)
//go:embed help.txt help_verbose.txt VERSION
var helpFS embed.FS
// Build-time variables
var (
compileTime = "unknown"
)
func showHelp() {
helpFileName := "help.txt"
if types.IsVerbose() {
helpFileName = "help_verbose.txt"
}
helpFile, err := helpFS.Open(helpFileName)
if err != nil {
fmt.Println("Error: Could not load help text.")
return
}
defer helpFile.Close()
helpContent, err := io.ReadAll(helpFile)
if err != nil {
fmt.Println("Error: Could not read help text.")
return
}
fmt.Println(string(helpContent))
}
func showVersion() {
versionFile, err := helpFS.Open("VERSION")
if err != nil {
fmt.Println("Error: Could not load version information.")
return
}
defer versionFile.Close()
versionContent, err := io.ReadAll(versionFile)
if err != nil {
fmt.Println("Error: Could not read version information.")
return
}
version := strings.TrimSpace(string(versionContent))
fmt.Println("Version: v" + version)
fmt.Println("Compiled:", compileTime)
}
func main() {
showHelpFlag := false
showVersionFlag := false
// Validate all arguments first
for i, arg := range os.Args {
if i == 0 { // Skip program name
continue
}
switch arg {
case "--help", "-h", "-help", "help":
showHelpFlag = true
case "--verbose", "-v", "-verbose":
types.SetVerbose(true)
case "--version":
showVersionFlag = true
default:
fmt.Printf("Error: Unknown option '%s'\n\n", arg)
fmt.Println("Valid options:")
fmt.Println(" --help, -h Show help information")
fmt.Println(" --verbose, -v Show verbose help information")
fmt.Println(" --version Show version information")
os.Exit(1)
}
}
if showVersionFlag {
showVersion()
return
}
if showHelpFlag {
showHelp()
return
}
// Normal execution
pwd, _ := os.Getwd()
logger.InfoBY("Current folder:", pwd)
// First check if templates folder exists and isn't empty
if err := types.ValidateTemplatesFolder(); err != nil {
fmt.Println("Error:", err)
fmt.Println("\nHere are the requirements to run goMaker:")
types.SetVerbose(false)
showHelp()
os.Exit(1)
}
codeBase, err := types.LoadCodebase()
if err != nil {
if strings.Contains(err.Error(), "could not find the templates directory") {
fmt.Println("Error:", err)
fmt.Println("\nHere are the requirements to run goMaker:")
types.SetVerbose(false)
showHelp()
os.Exit(1)
}
logger.Fatal(err)
}
codeBase.Generate()
}