diff --git a/main.go b/main.go index 8d4569d..61f4e84 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,12 @@ func main() { } return } + if *modfile == "" { + *modfile = path.Join(*moddir, "output.json") + } + + basename := path.Base(*modfile) + outputOps := file.NewJSONOps(path.Dir(*modfile)) m := &mod.Mod{ Lua: lua, @@ -62,14 +68,14 @@ func main() { Objs: objs, Objdirs: objdir, RootRead: rootops, - RootWrite: rootops, + RootWrite: outputOps, } err := m.GenerateFromConfig() if err != nil { fmt.Printf("generateMod() : %v\n", err) return } - err = m.Print() + err = m.Print(basename) if err != nil { log.Fatalf("printMod(...) : %v", err) } diff --git a/mod/generate.go b/mod/generate.go index c7f0118..e6460d3 100644 --- a/mod/generate.go +++ b/mod/generate.go @@ -120,8 +120,8 @@ func (m *Mod) generate(raw types.J) error { } // Print outputs internal representation of mod to json file with indents -func (m *Mod) Print() error { - return m.RootWrite.WriteObj(m.Data, "output.json") +func (m *Mod) Print(basename string) error { + return m.RootWrite.WriteObj(m.Data, basename) } func tryPut(d *types.J, from, to string, fun func(string) (interface{}, error)) { diff --git a/mod/generate_test.go b/mod/generate_test.go index 6a8fa55..66fff21 100644 --- a/mod/generate_test.go +++ b/mod/generate_test.go @@ -81,7 +81,7 @@ func TestGenerate(t *testing.T) { if err != nil { t.Fatalf("Error reading config %v", err) } - err = m.Print() + err = m.Print("output.json") if err != nil { t.Fatalf("Error printing config %v", err) } diff --git a/tests/e2e_test.go b/tests/e2e_test.go index c3fa809..398345b 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -78,7 +78,7 @@ func TestAllReverseThenBuild(t *testing.T) { if err != nil { t.Fatalf("generateMod() : %v\n", err) } - err = m.Print() + err = m.Print("output.json") if err != nil { t.Fatalf("printMod(...) : %v", err) }