kratos icon indicating copy to clipboard operation
kratos copied to clipboard

[BUG]Cannot create a service template under the specified path

Open tmdhhl opened this issue 2 years ago • 1 comments

What happened:

Cannot create a service template under the specified path, the new service template is always created at current working directory.

What you expected to happen:

Create a service template under the specified path

How to reproduce it (as minimally and precisely as possible):

image image

Anything else we need to know?:

It looks like this line is wrong, because the value of variable dir is os.Getwd().

// file path: cmd/kratos/internal/project/project.go
func run(cmd *cobra.Command, args []string) {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}
        ...
	go func() {
		if !nomod {
			done <- p.New(ctx, wd, repoURL, branch)
			return
		}
                ...
	}()
        ...
}

// file path: cmd/kratos/internal/project/new.go
// New new a project from remote repo.
func (p *Project) New(ctx context.Context, dir string, layout string, branch string) error {
	to := path.Join(dir, p.Name)
        ...
	if err := repo.CopyTo(ctx, to, p.Path, []string{".git", ".github"}); err != nil {
		return err
	}
        ...
}

Environment:

  • Kratos version (use kratos -v): kratos version v2.5.0
  • Go version (use go version): go version go1.18.4
  • OS (e.g: cat /etc/os-release): NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)"
  • Others:

tmdhhl avatar Sep 04 '22 03:09 tmdhhl

It is recommended to support the relative path and the absolute path, but the problem is not big, cd to the corresponding directory to execute again is not troublesome

yzrzr avatar Sep 09 '22 06:09 yzrzr

这样修改后,指定path,就无法实现指定mod了

Darrenzzy avatar Mar 16 '23 11:03 Darrenzzy