Skip to content

Commit

Permalink
Add progress steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Khang Ha committed Sep 5, 2020
1 parent 7682fd4 commit 5c42767
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
20 changes: 19 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
"time"

"github.com/khanghldk/gokit/constants"
"github.com/khanghldk/gokit/templates"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
},
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/khanghldk/gokit/constants"
"github.com/khanghldk/gokit/templates"
Expand Down Expand Up @@ -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!")
},
}

Expand Down
13 changes: 3 additions & 10 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}

3 changes: 3 additions & 0 deletions constants/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package constants

const Version = "v0.0.6"

0 comments on commit 5c42767

Please sign in to comment.