From ec50785015e5db9e294572f8f02051a991dfcd8b Mon Sep 17 00:00:00 2001 From: khoitx-ugaming <134240768+khoitx-ugaming@users.noreply.github.com> Date: Wed, 24 May 2023 11:07:36 +0700 Subject: [PATCH] Add abs path (#1) add absolute path option --- module/tagger.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/module/tagger.go b/module/tagger.go index 60c2b2f..b398655 100644 --- a/module/tagger.go +++ b/module/tagger.go @@ -5,6 +5,7 @@ import ( "go/parser" "go/printer" "go/token" + "os" "path/filepath" "strings" @@ -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) @@ -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) { @@ -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()