-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
48 lines (40 loc) · 1.13 KB
/
generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package generator
import (
"fmt"
"time"
"github.com/TadayoshiOtsuka/go-tady/internal/create/generator/engine"
"github.com/TadayoshiOtsuka/go-tady/pkg/config"
"github.com/TadayoshiOtsuka/go-tady/pkg/gomod"
"github.com/TadayoshiOtsuka/go-tady/pkg/utils"
"github.com/fatih/color"
"github.com/spf13/viper"
)
type IGenerator interface {
Do(src string, conf *config.ProjectConfig) error
}
type Generator struct {
engine engine.IEngine
}
func NewGenerator(engine engine.IEngine) IGenerator {
return &Generator{
engine: engine,
}
}
func (g *Generator) Do(src string, conf *config.ProjectConfig) error {
now := time.Now()
pjn := conf.Name
un := viper.GetString("username")
pn := fmt.Sprintf("github.com/%v/%v", un, pjn)
utils.PrintWithStartPrefix("Generate new project")
if err := g.engine.Start(src, pjn, pn); err != nil {
return err
}
utils.PrintDoneWithElapsedMillSec(now)
utils.PrintWithStartPrefix("Exec command 'go mod tidy'")
if err := gomod.Setup(pjn); err != nil {
return err
}
utils.PrintDoneWithElapsedMillSec(now)
utils.PrintWithElapsedMilliSec(color.GreenString("Successfully generated🎉 "), now)
return nil
}