From ee7d56a82c301152411a5dee03f65a087157c322 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 12 Sep 2024 09:17:50 +0200 Subject: [PATCH] Implement out directory --- .gitignore | 5 +---- main.go | 3 ++- types.go | 7 +++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index df340ef..e0870df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -Test.lua *.lua -avorion-docparser.exe -sync -test +avorion-docparser.exe \ No newline at end of file diff --git a/main.go b/main.go index 4600da9..9dd1b82 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ var fns = template.FuncMap{ } func main() { + outdir := flag.String("o", ".", "Output directory") flag.Parse() files := flag.Args() // if len(files) == 0 { @@ -70,7 +71,7 @@ func main() { return } - outfile, err := class.GetOutFile() + outfile, err := class.GetOutFile(*outdir) if err != nil { Error.Printf("Error creating output file: %v", err) return diff --git a/types.go b/types.go index 23c9dd5..65d7838 100644 --- a/types.go +++ b/types.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "path/filepath" "strings" ) @@ -39,7 +40,7 @@ type ( } ) -func (c *Class) GetOutFile() (*os.File, error) { +func (c *Class) GetOutFile(root string) (*os.File, error) { if c.ClassName == "" { return nil, fmt.Errorf("ClassName is empty") } @@ -48,7 +49,9 @@ func (c *Class) GetOutFile() (*os.File, error) { filename = strings.ReplaceAll(filename, "-", "") filename = strings.ReplaceAll(filename, ",", "") filename = strings.ReplaceAll(filename, ":", "") - f, err := os.Create(filename) + filePath := filepath.Join(root, filename) + filePath = filepath.Clean(filePath) + f, err := os.Create(filePath) if err != nil { return nil, err }