/
new.go
49 lines (43 loc) · 1.04 KB
/
new.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
49
package cli
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/gookit/color"
"github.com/urfave/cli/v2"
)
var newCmd = &cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "create an application",
Action: newApp,
}
func newApp(c *cli.Context) error {
// check cli args number
if c.NArg() != 1 {
fmt.Println("Usage: hyper new your_project_name")
os.Exit(1)
}
name := strings.ToLower(c.Args().Get(0))
path := filepath.Join(app.pwd, name)
_, err := os.Stat(path)
if err == nil {
color.Red.Println("app path had exists")
os.Exit(1)
}
err = os.Mkdir(path, os.ModePerm)
if err != nil {
color.Red.Printf("create app path failure %s\n", err.Error())
os.Exit(1)
}
fmt.Printf("start create %s's modules\n", name)
for _, module := range modules {
color.Bold.Printf("%s%s\n", strings.Repeat(" ", 2), module.Name)
if err := module.Create(filepath.Join(app.pwd, name), name); err != nil {
return err
}
}
color.Style{color.Green, color.OpBold}.Printf("%s create success, enjoy it!\n", name)
return nil
}