Skip to content

Commit d625c4b

Browse files
authored
feat(cmd): add --repo flag to kratos new command (#3789)
1 parent a7b85f5 commit d625c4b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cmd/kratos/internal/project/project.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ var CmdNew = &cobra.Command{
3131

3232
var (
3333
nomod bool
34+
repo string
3435
branch string
3536
timeout = "60s"
3637
)
3738

3839
func init() {
40+
CmdNew.Flags().StringVarP(&repo, "repo", "r", repo, "custom repo url")
3941
CmdNew.Flags().StringVarP(&branch, "branch", "b", branch, "repo branch")
4042
CmdNew.Flags().StringVarP(&timeout, "timeout", "t", timeout, "time out")
4143
CmdNew.Flags().BoolVarP(&nomod, "nomod", "", nomod, "retain go mod")
@@ -68,10 +70,15 @@ func run(_ *cobra.Command, args []string) {
6870
projectName, workingDir := processProjectParams(name, wd)
6971
p := &Project{Name: projectName}
7072
done := make(chan error, 1)
71-
repoURL, err := selectRepo()
72-
if err != nil {
73-
fmt.Fprintf(os.Stderr, "\033[31mERROR: failed to select repo(%s)\033[m\n", err.Error())
74-
return
73+
var repoURL string
74+
if repo != "" {
75+
repoURL = repo
76+
} else {
77+
repoURL, err = selectRepo()
78+
if err != nil {
79+
fmt.Fprintf(os.Stderr, "\033[31mERROR: failed to select repo(%s)\033[m\n", err.Error())
80+
return
81+
}
7582
}
7683
go func() {
7784
if !nomod {
@@ -86,7 +93,7 @@ func run(_ *cobra.Command, args []string) {
8693

8794
packagePath, e := filepath.Rel(projectRoot, filepath.Join(workingDir, projectName))
8895
if e != nil {
89-
done <- fmt.Errorf("🚫 failed to get relative path: %v", err)
96+
done <- fmt.Errorf("🚫 failed to get relative path: %v", e)
9097
return
9198
}
9299
packagePath = strings.ReplaceAll(packagePath, "\\", "/")

0 commit comments

Comments
 (0)