kratos
kratos copied to clipboard
[BUG]Cannot create a service template under the specified path
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):


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:
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
这样修改后,指定path,就无法实现指定mod了