Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding dry run option #286

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (r *RootApp) Run() error {
osp = &pkg.StdoutStreamProvider{}
} else {
osp = &pkg.FileOutputStreamProvider{
Config: r.Config,
BaseDir: r.Config.Output,
InPackage: r.Config.InPackage,
TestOnly: r.Config.TestOnly,
Expand Down Expand Up @@ -234,6 +235,7 @@ func (r *RootApp) Run() error {
}

visitor := &pkg.GeneratorVisitor{
Config: r.Config,
InPackage: r.Config.InPackage,
Note: r.Config.Note,
Osp: osp,
Expand All @@ -242,6 +244,7 @@ func (r *RootApp) Run() error {
}

walker := pkg.Walker{
Config: r.Config,
BaseDir: baseDir,
Recursive: recursive,
Filter: filter,
Expand Down
3 changes: 3 additions & 0 deletions pkg/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/rs/zerolog"
"github.com/vektra/mockery/pkg/config"
"github.com/vektra/mockery/pkg/logging"
)

Expand All @@ -26,6 +27,7 @@ func (this *StdoutStreamProvider) GetWriter(ctx context.Context, iface *Interfac
}

type FileOutputStreamProvider struct {
Config config.Config
BaseDir string
InPackage bool
TestOnly bool
Expand Down Expand Up @@ -70,6 +72,7 @@ func (this *FileOutputStreamProvider) GetWriter(ctx context.Context, iface *Inte
log = log.With().Str(logging.LogKeyPath, path).Logger()
ctx = log.WithContext(ctx)

log.Debug().Msgf("creating writer to file")
f, err := os.Create(path)
if err != nil {
return nil, err, func() error { return nil }
Expand Down
9 changes: 6 additions & 3 deletions pkg/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ func (this *GeneratorVisitor) VisitWalk(ctx context.Context, iface *Interface) e
}

log.Info().Msgf("Generating mock")
err = gen.Write(out)
if err != nil {
return err
if !this.Config.DryRun {
err = gen.Write(out)
if err != nil {
return err
}
}

return nil
}