added consistent _main
This commit is contained in:
@@ -82,13 +82,36 @@ func detectAndRunZip() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func runFiles(files []string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", r)
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
c := clyx.NewClyx("", defaultLibCode)
|
||||
for _, filePath := range files {
|
||||
content, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error executing %s: %v\n", filePath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
c.Run(string(content))
|
||||
}
|
||||
|
||||
if c.HasWord("_main") {
|
||||
c.Run("_main")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if detectAndRunZip() {
|
||||
return
|
||||
}
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
clyx.RunFile(os.Args[1], defaultLibCode)
|
||||
runFiles(os.Args[1:])
|
||||
} else {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
||||
Reference in New Issue
Block a user