Skip to content

Commit

Permalink
Add docs and hint in log message on how to enable force-file-write.
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonTClipp committed Jan 20, 2025
1 parent f02dab9 commit 53192c2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ tasks:
test.ci:
deps: [lint]
cmds:
- task: mocks.remove
- task: mocks.generate
- task: mocks
- task: test
- task: mocks.remove
- task: test.e2e

default:
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Parameter Descriptions
| `exclude-subpkg-regex` | :fontawesome-solid-x: | `#!yaml []` | A list of regular expressions that denote which subpackages should be excluded when `#!yaml recursive: true` |
| `exclude-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set along with `include-regex`, then interfaces which match `include-regex` but also match `exclude-regex` will not be generated. If `all` is set, or if `include-regex` is not set, then `exclude-regex` has no effect. |
| `filename` | :fontawesome-solid-check: | `#!yaml "mock_{{.InterfaceName}}.go"` | The name of the file the mock will reside in. |
| `force-file-write` | :fontawesome-solid-x: | `#!yaml false` | When set to `#!yaml force-file-write: true`, mockery will forcibly overwrite any existing files. |
| `formatter` | :fontawesome-solid-x: | `#!yaml "goimports"` | The formatter to use on the rendered template. Choices are: `gofmt`, `goimports`, `noop`. |
| `include-regex` | :fontawesome-solid-x: | `#!yaml ""` | When set, only interface names that match the expression will be generated. This setting is ignored if `all: True` is specified in the configuration. To further refine the interfaces generated, use `exclude-regex`. |
| `log-level` | :fontawesome-solid-x: | `#!yaml "info"` | Set the level of the logger |
Expand Down
1 change: 1 addition & 0 deletions e2e/test_infinite_mocking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# New mocks may legimitately be created, so we run mockery once first
num_files_before=$(find . -type f | wc -l)
export MOCKERY_FORCE_FILE_WRITE="true"
go run github.com/go-task/task/v3/cmd/task mocks.generate
num_files_after=$(find . -type f | wc -l)

Expand Down
2 changes: 1 addition & 1 deletion e2e/test_mockery_generation.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

go run github.com/go-task/task/v3/cmd/task mocks.generate
go run github.com/go-task/task/v3/cmd/task mocks
rt=$?
if [ $rt -ne 0 ]; then
echo "ERROR: non-zero return code from mockery"
Expand Down
8 changes: 0 additions & 8 deletions e2e/test_recursive_package_with_only_autogenerated_files.sh

This file was deleted.

4 changes: 2 additions & 2 deletions internal/cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ func (r *RootApp) Run() error {
fileLog.Err(err).Msg("can't determine if outfile exists")
return fmt.Errorf("determining if outfile exists: %w", err)
}
if outFileExists {
fileLog.Error().Msg("output file exists, can't write mocks")
if outFileExists && !packageConfig.Config.ForceFileWrite {
fileLog.Error().Bool("force-file-write", packageConfig.Config.ForceFileWrite).Msg("output file exists, can't write mocks")
return fmt.Errorf("outfile exists")
}

Expand Down
14 changes: 8 additions & 6 deletions template/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,14 @@ type Config struct {
ExcludeSubpkgRegex []string `koanf:"exclude-subpkg-regex"`
ExcludeRegex *string `koanf:"exclude-regex"`
FileName *string `koanf:"filename"`
Formatter *string `koanf:"formatter"`
IncludeRegex *string `koanf:"include-regex"`
LogLevel *string `koanf:"log-level"`
MockName *string `koanf:"mockname"`
PkgName *string `koanf:"pkgname"`
Recursive *bool `koanf:"recursive"`
// ForceFileWrite controls whether mockery will overwrite existing files when generating mocks. This is by default set to false.
ForceFileWrite bool `koanf:"force-file-write"`
Formatter *string `koanf:"formatter"`
IncludeRegex *string `koanf:"include-regex"`
LogLevel *string `koanf:"log-level"`
MockName *string `koanf:"mockname"`
PkgName *string `koanf:"pkgname"`
Recursive *bool `koanf:"recursive"`
// ReplaceType is a nested map of format map["package path"]["type name"]*ReplaceType
ReplaceType map[string]map[string]*ReplaceType `koanf:"replace-type"`
Template *string `koanf:"template"`
Expand Down

0 comments on commit 53192c2

Please sign in to comment.