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

feat: Changed the values of -source & -destination flags to relative … #176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func main() {
// is output into an already existing package.
outputPackagePath := *selfPackage
if outputPackagePath == "" && *destination != "" {
dstPath, err := filepath.Abs(filepath.Dir(*destination))
currentDir,err:=os.Getwd()
if err != nil {
log.Fatalf("%v",err)
}
dstPath, err := filepath.Abs(filepath.Dir(strings.Join([]string{currentDir,*destination},string(os.PathSeparator))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what filepath.Abs() already does if its input isn't an absolute path? Can you give some examples of what you're trying to achieve, please?

Separately, filepath.Join() should be used over strings.Join() in this case.

if err == nil {
pkgPath, err := parsePackageImport(dstPath)
if err == nil {
Expand Down
6 changes: 5 additions & 1 deletion mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ import (

// sourceMode generates mocks via source file.
func sourceMode(source string) (*model.Package, error) {
srcDir, err := filepath.Abs(filepath.Dir(source))
currentDir,err:=os.Getwd()
if err != nil {
return nil, fmt.Errorf("%v",err)
}
srcDir, err := filepath.Abs(filepath.Dir(strings.Join([]string{currentDir,source},string(os.PathSeparator))))
if err != nil {
return nil, fmt.Errorf("failed getting source directory: %v", err)
}
Expand Down