1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

Modify the command line tool to specify a custom layout repo when creating a new project (#814)

This commit is contained in:
包子
2021-04-06 15:46:43 +08:00
committed by GitHub
parent ae73827c93
commit 35d52295db
2 changed files with 10 additions and 8 deletions
+3 -7
View File
@@ -9,9 +9,6 @@ import (
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)
const (
serviceLayoutURL = "https://github.com/go-kratos/kratos-layout.git"
)
// Project is a project template.
type Project struct {
@@ -19,14 +16,13 @@ type Project struct {
}
// New new a project from remote repo.
func (p *Project) New(ctx context.Context, dir string) error {
func (p *Project) New(ctx context.Context, dir string, layout string) error {
to := path.Join(dir, p.Name)
if _, err := os.Stat(to); !os.IsNotExist(err) {
return fmt.Errorf("%s already exists", p.Name)
}
fmt.Printf("Creating service %s\n", p.Name)
repo := base.NewRepo(serviceLayoutURL)
fmt.Printf("Creating service %s, layout repo is %s\n", p.Name,layout)
repo := base.NewRepo(layout)
if err := repo.CopyTo(ctx, to, p.Name, []string{".git", ".github"}); err != nil {
return err
}
+7 -1
View File
@@ -17,6 +17,12 @@ var CmdNew = &cobra.Command{
Run: run,
}
var repoUrl string
func init() {
CmdNew.Flags().StringVarP(&repoUrl, "-repo-url", "r", "https://github.com/go-kratos/kratos-layout.git", "layout repo")
}
func run(cmd *cobra.Command, args []string) {
wd, err := os.Getwd()
if err != nil {
@@ -29,7 +35,7 @@ func run(cmd *cobra.Command, args []string) {
return
}
p := &Project{Name: args[0]}
if err := p.New(ctx, wd); err != nil {
if err := p.New(ctx, wd, repoUrl); err != nil {
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", err)
return
}