44 "bufio"
55 "bytes"
66 "context"
7- "errors"
87 "fmt"
98 "go/ast"
109 "os"
@@ -24,6 +23,7 @@ import (
2423 "github.com/knadh/koanf/v2"
2524 "github.com/rs/zerolog"
2625 "github.com/spf13/pflag"
26+ internalConfig "github.com/vektra/mockery/v3/internal/config"
2727 "github.com/vektra/mockery/v3/internal/logging"
2828 "github.com/vektra/mockery/v3/internal/stackerr"
2929 "github.com/vektra/mockery/v3/shared"
@@ -48,8 +48,8 @@ func NewInterface(name string, filename string, file *ast.File, pkg *packages.Pa
4848 }
4949}
5050
51- // Data is the data sent to the template for the config file.
52- type Data struct {
51+ // TemplateData is the data sent to the template for the config file.
52+ type TemplateData struct {
5353 // ConfigDir is the directory of where the mockery config file is located.
5454 ConfigDir string
5555 // InterfaceDir is the directory of the interface being mocked.
@@ -96,7 +96,7 @@ func NewDefaultKoanf(ctx context.Context) (*koanf.Koanf, error) {
9696}
9797
9898type RootConfig struct {
99- Config `koanf:",squash" yaml:",inline"`
99+ * Config `koanf:",squash" yaml:",inline"`
100100 Packages map [string ]* PackageConfig `koanf:"packages" yaml:"packages"`
101101 koanf * koanf.Koanf
102102 configFile * pathlib.Path
@@ -131,7 +131,7 @@ func NewRootConfig(
131131 return nil , nil , err
132132 }
133133 var rootConfig RootConfig = RootConfig {
134- Config : * conf ,
134+ Config : conf ,
135135 koanf : k ,
136136 }
137137
@@ -150,7 +150,7 @@ func NewRootConfig(
150150 }
151151 if configFile == nil {
152152 log .Debug ().Msg ("config file not specified, searching" )
153- configFile , err = findConfig ()
153+ configFile , err = internalConfig . FindConfig ()
154154 if err != nil {
155155 return nil , k , fmt .Errorf ("discovering mockery config: %w" , err )
156156 }
@@ -280,7 +280,7 @@ func (c *RootConfig) Initialize(ctx context.Context) error {
280280 pkgLog := log .With ().Str ("package-path" , pkgName ).Logger ()
281281 pkgCtx := pkgLog .WithContext (ctx )
282282
283- mergeConfigs (pkgCtx , c .Config , pkgConfig .Config )
283+ mergeConfigs (pkgCtx , * c .Config , pkgConfig .Config )
284284 if err := pkgConfig .Initialize (pkgCtx ); err != nil {
285285 return fmt .Errorf ("initializing root config: %w" , err )
286286 }
@@ -506,28 +506,6 @@ type Config struct {
506506 Version * bool `koanf:"version" yaml:"version,omitempty"`
507507}
508508
509- func findConfig () (* pathlib.Path , error ) {
510- cwd , err := os .Getwd ()
511- if err != nil {
512- return nil , fmt .Errorf ("getting current working directory: %w" , err )
513- }
514- currentPath := pathlib .NewPath (cwd )
515- for len (currentPath .Parts ()) != 1 {
516- for _ , confName := range []string {".mockery.yaml" , ".mockery.yml" } {
517- configPath := currentPath .Join (confName )
518- isFile , err := configPath .Exists ()
519- if err != nil {
520- return nil , fmt .Errorf ("checking if %s is file: %w" , configPath .String (), err )
521- }
522- if isFile {
523- return configPath , nil
524- }
525- }
526- currentPath = currentPath .Parent ()
527- }
528- return nil , errors .New ("mockery config file not found" )
529- }
530-
531509func (c * Config ) FilePath () * pathlib.Path {
532510 return pathlib .NewPath (* c .Dir ).Join (* c .FileName ).Clean ()
533511}
@@ -608,7 +586,7 @@ func (c *Config) ParseTemplates(ctx context.Context, iface *Interface, srcPkg *p
608586 }
609587 }
610588 // data is the struct sent to the template parser
611- data := Data {
589+ data := TemplateData {
612590 ConfigDir : filepath .Dir (* c .ConfigFile ),
613591 InterfaceDir : interfaceDir ,
614592 InterfaceDirRelative : interfaceDirRelative ,
0 commit comments