chore: output write scaffolding

This commit is contained in:
2026-04-17 12:56:20 +01:00
parent 05fadf3ef2
commit 01f59b8770
+13 -8
View File
@@ -1,23 +1,26 @@
package main package main
import ( import (
"fmt"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
// "strings" "strings"
) )
func process(inputPath string) { func process(inputPath string) error {
// outputPath := strings.Replace(inputPath, ".jack", ".xml", 1) outputPath := strings.Replace(inputPath, ".jack", ".xml", 1)
source, err := os.ReadFile(inputPath) source, err := os.ReadFile(inputPath)
if err != nil { if err != nil {
panic(err) return err
} }
fmt.Println(string(source)) if err := os.WriteFile(outputPath, source, 0644); err != nil {
return err
}
return nil
} }
func walker(path string, entry fs.DirEntry, err error) error { func walker(path string, entry fs.DirEntry, err error) error {
@@ -26,7 +29,7 @@ func walker(path string, entry fs.DirEntry, err error) error {
} }
if match, _ := regexp.MatchString(".+\\.jack$", path); match { if match, _ := regexp.MatchString(".+\\.jack$", path); match {
process(path) return process(path)
} }
return nil return nil
@@ -59,5 +62,7 @@ func main() {
panic("You must provide a path for a Jack file or a directory that contains Jack files to compile!") panic("You must provide a path for a Jack file or a directory that contains Jack files to compile!")
} }
process(args[1]) if err := process(args[1]); err != nil {
panic(err)
}
} }