This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 2ab559e37b6db567e9c1ec25e94917275baf272e
Author: abeizn <[email protected]>
AuthorDate: Wed Jul 20 17:07:04 2022 +0800

    fix: create_migration adapt new migration rules and add verity purpose
---
 generator/cmd/create_migration.go | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/generator/cmd/create_migration.go 
b/generator/cmd/create_migration.go
index 5417de9b..f747b9bb 100644
--- a/generator/cmd/create_migration.go
+++ b/generator/cmd/create_migration.go
@@ -20,14 +20,15 @@ package cmd
 import (
        "errors"
        "fmt"
-       "github.com/apache/incubator-devlake/generator/util"
-       "github.com/manifoldco/promptui"
-       "github.com/spf13/cobra"
        "io/ioutil"
        "os"
        "path/filepath"
        "regexp"
        "time"
+
+       "github.com/apache/incubator-devlake/generator/util"
+       "github.com/manifoldco/promptui"
+       "github.com/spf13/cobra"
 )
 
 func init() {
@@ -74,13 +75,8 @@ If framework passed, generator will create a new migration 
in models/migrationsc
                cobra.CheckErr(err)
 
                prompt := promptui.Prompt{
-                       Label: "purpose",
-                       Validate: func(input string) error {
-                               if input == `` {
-                                       return errors.New("purpose require")
-                               }
-                               return nil
-                       },
+                       Label:    "purpose",
+                       Validate: purposeNotExistValidate,
                }
                purpose, err = prompt.Run()
                cobra.CheckErr(err)
@@ -122,3 +118,15 @@ If framework passed, generator will create a new migration 
in models/migrationsc
                }
        },
 }
+
+func purposeNotExistValidate(input string) error {
+       if input == `` {
+               return errors.New("purpose require")
+       }
+       snakeNameReg := regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_]*$`)
+       if !snakeNameReg.MatchString(input) {
+               return errors.New("purpose invalid (start with a-z and consist 
with a-z0-9_)")
+       }
+
+       return nil
+}

Reply via email to