@@ -20,7 +20,6 @@ import (
2020 "text/template"
2121
2222 "github.com/brunoga/deep"
23- "github.com/chigopher/pathlib"
2423 "github.com/go-viper/mapstructure/v2"
2524 koanfYAML "github.com/knadh/koanf/parsers/yaml"
2625 "github.com/knadh/koanf/providers/env"
@@ -93,14 +92,14 @@ type RootConfig struct {
9392 Config `koanf:",squash" yaml:",inline"`
9493 Packages map [string ]* PackageConfig `koanf:"packages" yaml:"packages"`
9594 koanf * koanf.Koanf
96- configFile * pathlib. Path
95+ configFile string
9796}
9897
9998func NewRootConfig (
10099 ctx context.Context ,
101100 flags * pflag.FlagSet ,
102101) (* RootConfig , * koanf.Koanf , error ) {
103- var configFile * pathlib. Path
102+ var configFile string
104103
105104 log := zerolog .Ctx (ctx )
106105 var err error
@@ -131,24 +130,24 @@ func NewRootConfig(
131130
132131 configFileFromEnv := os .Getenv ("MOCKERY_CONFIG" )
133132 if configFileFromEnv != "" {
134- configFile = pathlib . NewPath ( configFileFromEnv )
133+ configFile = configFileFromEnv
135134 }
136- if configFile == nil {
135+ if configFile == "" {
137136 configFileFromFlags , err := flags .GetString ("config" )
138137 if err != nil {
139138 return nil , nil , fmt .Errorf ("getting --config from flags: %w" , err )
140139 }
141140 if configFileFromFlags != "" {
142- configFile = pathlib . NewPath ( configFileFromFlags )
141+ configFile = configFileFromFlags
143142 }
144143 }
145- if configFile == nil {
144+ if configFile == "" {
146145 log .Debug ().Msg ("config file not specified, searching" )
147146 configFile , err = internalConfig .FindConfig ()
148147 if err != nil {
149148 return nil , k , fmt .Errorf ("discovering mockery config: %w" , err )
150149 }
151- log .Debug ().Str ("config-file" , configFile . String () ).Msg ("config file found" )
150+ log .Debug ().Str ("config-file" , configFile ).Msg ("config file found" )
152151 }
153152 rootConfig .configFile = configFile
154153
@@ -187,7 +186,7 @@ func NewRootConfig(
187186 return nil , nil , stackerr .NewStackErr (err )
188187 }
189188
190- if err := k .Load (file .Provider (configFile . String () ), koanfYAML .Parser ()); err != nil {
189+ if err := k .Load (file .Provider (configFile ), koanfYAML .Parser ()); err != nil {
191190 return nil , k , fmt .Errorf ("loading config file: %w" , err )
192191 }
193192
@@ -212,7 +211,7 @@ func NewRootConfig(
212211 return & rootConfig , k , nil
213212}
214213
215- func (c * RootConfig ) ConfigFileUsed () * pathlib. Path {
214+ func (c * RootConfig ) ConfigFileUsed () string {
216215 return c .configFile
217216}
218217
@@ -551,8 +550,8 @@ func (c Config) koanfTagNames() map[string]struct{} {
551550 return tags
552551}
553552
554- func (c * Config ) FilePath () * pathlib. Path {
555- return pathlib . NewPath ( * c . Dir ) .Join (* c .FileName ). Clean ( )
553+ func (c * Config ) FilePath () string {
554+ return filepath . ToSlash ( filepath . Clean ( filepath .Join (* c .Dir , * c . FileName )) )
556555}
557556
558557func (c * Config ) ShouldExcludeSubpkg (pkgPath string ) bool {
@@ -595,32 +594,35 @@ func (c *Config) ParseTemplates(
595594 if err != nil {
596595 return fmt .Errorf ("get working directory: %w" , err )
597596 }
598- interfaceDirPath := pathlib .NewPath (ifaceFilePath ).Parent ()
599- interfaceDirRelativePath , err := interfaceDirPath .RelativeToStr (workingDir )
597+ workingDir = filepath .ToSlash (workingDir )
598+ ifaceFilePath = filepath .ToSlash (filepath .Clean (ifaceFilePath ))
599+ interfaceDirPath := filepath .ToSlash (filepath .Dir (ifaceFilePath ))
600+ interfaceDirRelativePath , err := filepath .Rel (filepath .FromSlash (workingDir ), filepath .FromSlash (interfaceDirPath ))
600601
601602 var interfaceDirRelative string
602603
603604 if err != nil {
604605 log .Debug ().
605606 Err (err ).
606607 Str ("working-dir" , workingDir ).
607- Str ("interfaceDirPath" , interfaceDirPath . String () ).
608- Str ("interface-dir-relative-path" , interfaceDirRelativePath . String () ).
608+ Str ("interfaceDirPath" , interfaceDirPath ).
609+ Str ("interface-dir-relative-path" , interfaceDirRelativePath ).
609610 Msg ("can't make path relative to working dir, setting to './'" )
610611 interfaceDirRelative = "."
611612 } else {
613+ interfaceDirRelativePath = filepath .ToSlash (interfaceDirRelativePath )
612614 log .Debug ().
613615 Str ("working-dir" , workingDir ).
614- Str ("interfaceDirPath" , interfaceDirPath . String () ).
615- Str ("interface-dir-relative-path" , interfaceDirRelativePath . String () ).
616+ Str ("interfaceDirPath" , interfaceDirPath ).
617+ Str ("interface-dir-relative-path" , interfaceDirRelativePath ).
616618 Msg ("found relative path" )
617- interfaceDirRelative = interfaceDirRelativePath . String ()
619+ interfaceDirRelative = interfaceDirRelativePath
618620 }
619621
620622 // data is the struct sent to the template parser
621623 data := TemplateData {
622624 ConfigDir : filepath .Dir (* c .ConfigFile ),
623- InterfaceDir : interfaceDirPath . String () ,
625+ InterfaceDir : interfaceDirPath ,
624626 InterfaceDirRelative : interfaceDirRelative ,
625627 InterfaceFile : ifaceFilePath ,
626628 InterfaceName : ifaceName ,
0 commit comments