Skip to content

Commit

Permalink
Add abs path (#1)
Browse files Browse the repository at this point in the history
add absolute path option
  • Loading branch information
khoitx-ugaming authored May 24, 2023
1 parent 70af775 commit ec50785
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions module/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"go/parser"
"go/printer"
"go/token"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -47,6 +48,8 @@ func (m mod) Execute(targets map[string]pgs.File, packages map[string]pgs.Packag
}

module := m.Parameters().Str("module")
outdir := m.Parameters().Str("outdir")
outAbsDir := m.Parameters().Str("outabsdir")

extractor := newTagExtractor(m, m.Context, autoTags)

Expand All @@ -57,14 +60,14 @@ func (m mod) Execute(targets map[string]pgs.File, packages map[string]pgs.Packag

gfname := m.Context.OutputPath(f).SetExt(".go").String()

outdir := m.Parameters().Str("outdir")
filename := gfname
if outdir != "" {
if len(outAbsDir) > 0 {
filename = filepath.Join(outAbsDir, gfname)
} else if outdir != "" {
filename = filepath.Join(outdir, gfname)
}

if module != "" {

filename = strings.ReplaceAll(filename, string(filepath.Separator), "/")
trim := module + "/"
if !strings.HasPrefix(filename, trim) {
Expand All @@ -83,7 +86,11 @@ func (m mod) Execute(targets map[string]pgs.File, packages map[string]pgs.Packag
var buf strings.Builder
m.CheckErr(printer.Fprint(&buf, fs, fn))

m.OverwriteGeneratorFile(filename, buf.String())
if len(outAbsDir) > 0 {
m.OverwriteCustomFile(filename, buf.String(), os.ModePerm)
} else {
m.OverwriteGeneratorFile(filename, buf.String())
}
}

return m.Artifacts()
Expand Down

0 comments on commit ec50785

Please sign in to comment.