Skip to content

Commit

Permalink
feat: allow provide dynamic input path and name_prefix using only GO PKG
Browse files Browse the repository at this point in the history
  • Loading branch information
moisespsena committed Apr 16, 2019
1 parent c0c4a9b commit 92c2fbd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion config_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"strings"

"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -48,9 +49,27 @@ type ManyConfigInput struct {
Recursive bool
Ignore IgnoreSlice
IgnoreGlob IgnoreGlobSlice `mapstructure:"ignore_glob" yaml:"ignore_glob"`
Pkg string
}

func (i ManyConfigInput) Config() (configs []*InputConfig, err error) {
func (i *ManyConfigInput) GetPkg() string {
if i.Pkg == "" {
i.Pkg = path_helpers.StripGoPath(i.Path)
}
return i.Pkg
}

func (i *ManyConfigInput) Config() (configs []*InputConfig, err error) {
if i.Path == "" {
log.Warnf("input path not set", i.Path)
return
}

if strings.HasPrefix(i.Path, "go:") {
i.Pkg = i.Path[3:]
_, i.Path = path_helpers.ResolveGoSrcPath(i.Pkg)
}

if _, err = os.Stat(i.Path); err != nil {
if os.IsNotExist(err) {
log.Warnf("input %q does not exists", i.Path)
Expand All @@ -59,6 +78,12 @@ func (i ManyConfigInput) Config() (configs []*InputConfig, err error) {
return
}

if i.NamePrefix == "_" {
i.NamePrefix = i.GetPkg()
} else if strings.Contains(i.NamePrefix, "$PKG") {
i.NamePrefix = path.Clean(strings.Replace(i.NamePrefix, "$PKG", i.GetPkg(), 1))
}

xbinputFile := filepath.Join(i.Path, ".xbinputs.yml")
if _, err = os.Stat(xbinputFile); err == nil {
if i.Prefix == "_" {
Expand Down

0 comments on commit 92c2fbd

Please sign in to comment.