/
cli.go
executable file
·73 lines (61 loc) · 1.2 KB
/
cli.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"fmt"
"log"
"os"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var (
appName string
moduleName string
goVersion string
parentDir string
debugMode bool
)
func App() {
app := cli.NewApp()
app.Name = "goc-cli"
app.Version = "v0.0.1"
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("version: %s\n", c.App.Version)
}
app.Usage = "An interactive cli to create go app"
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "new",
Aliases: []string{"n"},
Usage: "create new go app",
Destination: &appName,
Required: true,
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"D"},
Usage: "Enable debug mode",
Destination: &debugMode,
},
}
app.Action = func(c *cli.Context) (err error) {
if debugMode {
logrus.SetLevel(logrus.DebugLevel)
}
goVersion, err = promptGoVersion()
if err != nil {
return err
}
moduleName, err = promptModule()
if err != nil {
return err
}
if err := Generator(); err != nil {
return err
}
fmt.Printf("Congratulation!👏 Go ahead with %s 👊\n", appName)
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}