Skip to content

Commit

Permalink
Fixes vektra#769 : Avoid directory and empty files creation when dry …
Browse files Browse the repository at this point in the history
…run mode is enabled

- dynamically set dry run config during Outputter initialization
  • Loading branch information
harshvardhan.rajdan committed Apr 27, 2024
1 parent d2b16e0 commit 7e4be6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/mockery.go
Expand Up @@ -269,7 +269,7 @@ func (r *RootApp) Run() error {
}
ifaceLog.Debug().Msg("config specifies to generate this interface")

outputter := pkg.NewOutputter(&r.Config, boilerplate, true)
outputter := pkg.NewOutputter(&r.Config, boilerplate, r.Config.DryRun)
if err := outputter.Generate(ifaceCtx, iface); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/outputter.go
Expand Up @@ -351,6 +351,11 @@ func (m *Outputter) Generate(ctx context.Context, iface *Interface) error {
return err
}

// If we're in dry-run mode, don't write the mock to disk
if m.dryRun {
continue
}

outputPath := pathlib.NewPath(interfaceConfig.Dir).Join(interfaceConfig.FileName)
if err := outputPath.Parent().MkdirAll(); err != nil {
return stackerr.NewStackErrf(err, "failed to mkdir parents of: %v", outputPath)
Expand Down

0 comments on commit 7e4be6f

Please sign in to comment.