Skip to content

Commit

Permalink
Merge pull request #285 from LandonTClipp/semver_and_structure
Browse files Browse the repository at this point in the history
Modifying semver and restructuring package
  • Loading branch information
LandonTClipp authored Jun 15, 2020
2 parents d08594a + fbcecb3 commit 264db4c
Show file tree
Hide file tree
Showing 94 changed files with 148 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test:
go test ./...

fixture:
mockery --print --dir pkg/mockery/fixtures --name RequesterVariadic > pkg/mockery/fixtures/mocks/requester_variadic.go
mockery --print --dir pkg/fixtures --name RequesterVariadic > pkg/fixtures/mocks/requester_variadic.go

install:
go install ./...
Expand Down
48 changes: 13 additions & 35 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vektra/mockery/pkg/mockery"
"github.com/vektra/mockery/pkg"
"github.com/vektra/mockery/pkg/config"
"github.com/vektra/mockery/pkg/logging"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/tools/go/packages"
)
Expand Down Expand Up @@ -60,32 +62,6 @@ func Execute() {
}
}

type Config struct {
All bool
BuildTags string
Case string
Config string
Cpuprofile string
Dir string
FileName string
InPackage bool
KeepTree bool
LogLevel string `mapstructure:"log-level"`
Name string
Note string
Outpkg string
Output string
Print bool
Profile string
Quiet bool
Recursive bool
SrcPkg string
StructName string
Tags string
TestOnly bool
Version bool
}

func init() {
cobra.OnInitialize(initConfig)

Expand All @@ -111,6 +87,7 @@ func init() {
pFlags.String("structname", "", "name of generated struct (only works with -name and no regex)")
pFlags.String("log-level", "info", "Level of logging")
pFlags.String("srcpkg", "", "source pkg to search for interfaces")
pFlags.BoolP("dry-run", "d", false, "Do a dry run, don't modify any files")

viper.BindPFlags(pFlags)
}
Expand Down Expand Up @@ -144,7 +121,7 @@ func initConfig() {
const regexMetadataChars = "\\.+*?()|[]{}^$"

type RootApp struct {
Config
config.Config
}

func GetRootAppFromViper(v *viper.Viper) (*RootApp, error) {
Expand Down Expand Up @@ -172,11 +149,12 @@ func (r *RootApp) Run() error {
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
return err
}
log = log.With().Bool(logging.LogKeyDryRun, r.Config.DryRun).Logger()
log.Info().Msgf("Starting mockery")
ctx := log.WithContext(context.Background())

if r.Config.Version {
fmt.Println(mockery.SemVer)
fmt.Println(config.SemVer)
return nil
} else if r.Config.Name != "" && r.Config.All {
log.Fatal().Msgf("Specify --name or --all, but not both")
Expand Down Expand Up @@ -216,11 +194,11 @@ func (r *RootApp) Run() error {
defer pprof.StopCPUProfile()
}

var osp mockery.OutputStreamProvider
var osp pkg.OutputStreamProvider
if r.Config.Print {
osp = &mockery.StdoutStreamProvider{}
osp = &pkg.StdoutStreamProvider{}
} else {
osp = &mockery.FileOutputStreamProvider{
osp = &pkg.FileOutputStreamProvider{
BaseDir: r.Config.Output,
InPackage: r.Config.InPackage,
TestOnly: r.Config.TestOnly,
Expand Down Expand Up @@ -255,15 +233,15 @@ func (r *RootApp) Run() error {
baseDir = filepath.Dir(pkg.GoFiles[0])
}

visitor := &mockery.GeneratorVisitor{
visitor := &pkg.GeneratorVisitor{
InPackage: r.Config.InPackage,
Note: r.Config.Note,
Osp: osp,
PackageName: r.Config.Outpkg,
StructName: r.Config.StructName,
}

walker := mockery.Walker{
walker := pkg.Walker{
BaseDir: baseDir,
Recursive: recursive,
Filter: filter,
Expand Down Expand Up @@ -302,7 +280,7 @@ func getLogger(levelStr string) (zerolog.Logger, error) {
Hook(timeHook{}).
Level(level).
With().
Str("version", mockery.SemVer).
Str("version", config.SemVer).
Logger()

return log, nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/showconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vektra/mockery/pkg/config"
"gopkg.in/yaml.v2"
)

Expand All @@ -17,7 +18,7 @@ var showconfigCmd = &cobra.Command{
This initializes viper and prints out the merged configuration between
config files, environment variables, and CLI flags.`,
RunE: func(cmd *cobra.Command, args []string) error {
config := &Config{}
config := &config.Config{}
if err := viper.UnmarshalExact(config); err != nil {
return errors.Wrapf(err, "failed to unmarshal config")
}
Expand Down
4 changes: 2 additions & 2 deletions hack/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ${GOPATH}/bin/mockery -all -recursive -cpuprofile="mockery.prof" -dir="mockery/f
verify

reset
${GOPATH}/bin/mockery -all -recursive -cpuprofile="mockery.prof" -srcpkg github.com/vektra/mockery/pkg/mockery/fixtures
${GOPATH}/bin/mockery -all -recursive -cpuprofile="mockery.prof" -srcpkg github.com/vektra/mockery/pkg/fixtures
verify


Expand All @@ -36,5 +36,5 @@ docker run -v $(pwd):/src -w /src --user=$(id -u):$(id -g) vektra/mockery -all -
verify

reset
docker run -v $(pwd):/src -w /src --user=$(id -u):$(id -g) vektra/mockery -all -recursive -cpuprofile="mockery.prof" -srcpkg github.com/vektra/mockery/pkg/mockery/fixtures
docker run -v $(pwd):/src -w /src --user=$(id -u):$(id -g) vektra/mockery -all -recursive -cpuprofile="mockery.prof" -srcpkg github.com/vektra/mockery/pkg/fixtures
verify
2 changes: 1 addition & 1 deletion mocks/cmd/stackTracer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mocks/pkg/mockery/fixtures/A.go → mocks/pkg/fixtures/A.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 264db4c

Please sign in to comment.