assets builder tools (#39)
Reviewed-on: #39 Reviewed-by: xtul <mpiasecki720@protonmail.com>
This commit was merged in pull request #39.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/assets/mdl"
|
||||
)
|
||||
|
||||
// mdlExt is the file set shared by the mdl commands.
|
||||
var mdlExt = map[string]bool{".mdl": true}
|
||||
|
||||
// runCheckMDL reports uncompiled ASCII .mdl files and model-name mismatches.
|
||||
// Read-only. Exit exitFail if any problem is found.
|
||||
func runCheckMDL(args []string, stdout, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet("check-mdl", flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
nonRecursive := fs.Bool("non-recursive", false, "do not descend into subdirectories")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return exitUsage
|
||||
}
|
||||
paths := fs.Args()
|
||||
if len(paths) == 0 {
|
||||
fmt.Fprintln(stderr, "assets check-mdl: usage: check-mdl <path>...")
|
||||
return exitUsage
|
||||
}
|
||||
|
||||
files, err := walk(paths, mdlExt, !*nonRecursive)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, "assets check-mdl:", err)
|
||||
return exitUsage
|
||||
}
|
||||
|
||||
fail := false
|
||||
for _, f := range files {
|
||||
ascii, err := mdl.IsASCII(f)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, "assets check-mdl:", err)
|
||||
return exitTool
|
||||
}
|
||||
if ascii {
|
||||
fmt.Fprintf(stderr, "uncompiled ascii mdl: %s\n", f)
|
||||
fail = true
|
||||
}
|
||||
mismatches, err := mdl.CheckNames(f)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, "assets check-mdl:", err)
|
||||
return exitTool
|
||||
}
|
||||
expected := mdl.ExpectedName(f)
|
||||
for _, m := range mismatches {
|
||||
if m.Line == 0 {
|
||||
fmt.Fprintf(stderr, "%s: mdl model-name mismatch: root node is %s, expected %s\n", f, m.Got, expected)
|
||||
} else {
|
||||
fmt.Fprintf(stderr, "%s: mdl model-name mismatch: line %d: %s is %s, expected %s\n", f, m.Line, m.What, m.Got, expected)
|
||||
}
|
||||
fail = true
|
||||
}
|
||||
}
|
||||
if fail {
|
||||
fmt.Fprintln(stderr, "check-mdl: found broken or uncompiled .mdl file(s)")
|
||||
return exitFail
|
||||
}
|
||||
fmt.Fprintln(stdout, "check-mdl: OK")
|
||||
return exitOK
|
||||
}
|
||||
Reference in New Issue
Block a user