Skip to content

Commit

Permalink
Merge pull request #42 from argonui/name_outputfile
Browse files Browse the repository at this point in the history
Allow modfile to be used to specify location
  • Loading branch information
argonui authored Nov 16, 2022
2 parents 42cebe6 + ca379e5 commit 0456abb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,27 @@ 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,
Modsettings: ms,
Objs: objs,
Objdirs: objdir,
RootRead: rootops,
RootWrite: rootops,
RootWrite: outputOps,
}
err := m.GenerateFromConfig()
if err != nil {
fmt.Printf("generateMod(<config>) : %v\n", err)
return
}
err = m.Print()
err = m.Print(basename)
if err != nil {
log.Fatalf("printMod(...) : %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions mod/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion mod/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestAllReverseThenBuild(t *testing.T) {
if err != nil {
t.Fatalf("generateMod(<config>) : %v\n", err)
}
err = m.Print()
err = m.Print("output.json")
if err != nil {
t.Fatalf("printMod(...) : %v", err)
}
Expand Down

0 comments on commit 0456abb

Please sign in to comment.