Skip to content

Commit

Permalink
Deprecate GOROOT/GOPATH anchoring when deriving package name
Browse files Browse the repository at this point in the history
  • Loading branch information
kelveny committed Jun 16, 2021
1 parent 1fe0cc1 commit 67495bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/mockcompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Execute() {
if cfg := loadConfig(); cfg != nil {
logger.Log(logger.VERBOSE, "Found mockcompose YAML configuration, ignore command line options\n")

derivedPkg := gofile.DerivePackage()
derivedPkg := gofile.DerivePackage(false)
for _, options := range cfg.Mockcompose {
if options.MockPkg == "" {
options.MockPkg = derivedPkg
Expand All @@ -178,7 +178,7 @@ func Execute() {
}

if *mockPkg == "" {
*mockPkg = gofile.DerivePackage()
*mockPkg = gofile.DerivePackage(false)

logger.Log(logger.VERBOSE, "Derive package name as: %s\n", *mockPkg)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/gofile/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import (
"github.com/kelveny/mockcompose/pkg/logger"
)

func DerivePackage() string {
func DerivePackage(anchor bool) string {
path, err := filepath.Abs("")
if err != nil {
logger.Log(logger.ERROR, "Error in accessing file system. error: %s\n", err)
os.Exit(1)
}

if path, ok := StripGopath(path); ok {
return path
if anchor {
return path
}
return filepath.Base(path)
}

return filepath.Base(path)
Expand Down

0 comments on commit 67495bd

Please sign in to comment.