From 5c42767f232d7a1aa8aec933deda89776ae1b12e Mon Sep 17 00:00:00 2001 From: Khang Ha Date: Sat, 5 Sep 2020 16:56:41 +0700 Subject: [PATCH] Add progress steps --- cmd/init.go | 20 +++++++++++++++++++- cmd/new.go | 15 +++++++++++++++ cmd/version.go | 13 +++---------- constants/version.go | 3 +++ 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 constants/version.go diff --git a/cmd/init.go b/cmd/init.go index 184be1e..1912309 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "time" "github.com/khanghldk/gokit/constants" "github.com/khanghldk/gokit/templates" @@ -35,8 +36,12 @@ var initCmd = &cobra.Command{ basePath = scanner.Text() } + fmt.Println(constants.ColorYellow, "======Initialize=====") + rootFolder := projectName folders := []string{"cmd", "adapters", "migrations", "configs", "errors", "dtos", "utils", "controllers", "repositories", "services"} + fmt.Println("Create base folders...") + time.Sleep(time.Second) err := os.Mkdir(rootFolder, os.ModePerm) if err != nil { logrus.Fatal(err) @@ -59,6 +64,8 @@ var initCmd = &cobra.Command{ BasePath: basePath, } + fmt.Println("Create base files...") + time.Sleep(time.Second) err = utils.CreateFile(fmt.Sprintf("./%v/%v", "cmd", "main.go"), []byte(utils.StandardizedTemplate(templates.MainContent, params))) if err != nil { logrus.Fatal(err) @@ -114,7 +121,10 @@ var initCmd = &cobra.Command{ logrus.Fatal(err) } - err = utils.CreateFile(fmt.Sprintf("./%v",".env"), []byte(templates.EnvTemplate)) + err = utils.CreateFile(fmt.Sprintf("./%v", ".env"), []byte(templates.EnvTemplate)) + + fmt.Println("Go mod init...") + time.Sleep(time.Second) folder, _ := os.Getwd() output, err := utils.GoModInit(moduleName, folder) @@ -127,10 +137,18 @@ var initCmd = &cobra.Command{ logrus.Fatalf("Error: %v, Output: %v", err, output) } + fmt.Println("Git init...") + time.Sleep(time.Second) + output, err = utils.GitInit(folder) if err != nil { logrus.Fatalf("Error: %v, Output: %v", err, output) } + + fmt.Println("Finish initialization!") + time.Sleep(time.Second / 4) + fmt.Print(constants.ColorBlue, fmt.Sprintf("Move to your work by: $cd %v", projectName)) + fmt.Println() }, } diff --git a/cmd/new.go b/cmd/new.go index 4468fac..95d738e 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strings" + "time" "github.com/khanghldk/gokit/constants" "github.com/khanghldk/gokit/templates" @@ -36,36 +37,50 @@ var newCmd = &cobra.Command{ switch genType { case "controller": + fmt.Println(constants.ColorYellow, "Generate controller...") + time.Sleep(time.Second) err := GenerateController(params) if err != nil { logrus.Fatal(err) } + fmt.Println(constants.ColorYellow, "Generate service...") + time.Sleep(time.Second) err = GenerateService(params) if err != nil { logrus.Fatal(err) } + fmt.Println(constants.ColorYellow, "Generate repository...") + time.Sleep(time.Second) err = GenerateRepository(params) if err != nil { logrus.Fatal(err) } case "service": + fmt.Println(constants.ColorYellow, "Generate serivce...") + time.Sleep(time.Second) err := GenerateService(params) if err != nil { logrus.Fatal(err) } + fmt.Println(constants.ColorYellow, "Generate repository...") + time.Sleep(time.Second) err = GenerateRepository(params) if err != nil { logrus.Fatal(err) } case "repository": + fmt.Println(constants.ColorYellow, "Generate repository...") + time.Sleep(time.Second) err := GenerateRepository(params) if err != nil { logrus.Fatal(err) } } + + fmt.Println("Finish!") }, } diff --git a/cmd/version.go b/cmd/version.go index a02aa18..9f8a377 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,8 +3,7 @@ package cmd import ( "fmt" - "github.com/khanghldk/gokit/utils" - "github.com/sirupsen/logrus" + "github.com/khanghldk/gokit/constants" "github.com/spf13/cobra" ) @@ -14,17 +13,11 @@ var verCmd = &cobra.Command{ Aliases: []string{"v"}, Short: "Get version", Run: func(cmd *cobra.Command, args []string) { - ver, err := utils.GetVersion() - if err != nil { - logrus.Error("invalid version") - return - } - - fmt.Printf("gokit version %v", ver) + message := fmt.Sprintf("gokit version %v", constants.Version) + fmt.Println(constants.ColorYellow, message) }, } func init() { RootCmd.AddCommand(verCmd) } - diff --git a/constants/version.go b/constants/version.go new file mode 100644 index 0000000..05f32b0 --- /dev/null +++ b/constants/version.go @@ -0,0 +1,3 @@ +package constants + +const Version = "v0.0.6"