-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (87 loc) · 1.84 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"lxc/react-tmpl-cli/generator"
"lxc/react-tmpl-cli/utils"
"github.com/urfave/cli/v2"
"log"
"os"
"os/user"
)
func main() {
var err error
user, err := user.Current()
if err != nil {
panic(err)
}
templatesDir := user.HomeDir + "/" + ".react-tmpl-cli/templates"
app := &cli.App{
Commands: []*cli.Command{
{
Name: "add",
Aliases: []string{"a"},
Usage: "add a task to the list",
Action: func(c *cli.Context) error {
fmt.Println("added task: ", c.Args().First())
return nil
},
},
{
Name: "complete",
Aliases: []string{"c"},
Usage: "complete a task on the list",
Action: func(c *cli.Context) error {
fmt.Println("completed task: ", c.Args().First())
return nil
},
},
{
Name: "generate",
Aliases: []string{"g"},
Usage: "generate react components",
Subcommands: []*cli.Command{
{
Name: "fc",
Usage: "add a new function component",
Action: func(c *cli.Context) error {
var err error
dir, fileName := utils.GetDirAndFileName(c.Args().First())
err = generator.GenerateReactFc(
templatesDir,
dir,
fileName,
)
return err
},
},
{
Name: "page",
Usage: "add a new page",
Action: func(c *cli.Context) error {
var err error
dir, fileName := utils.GetDirAndFileName(c.Args().First())
err = generator.GeneratePage(
templatesDir,
dir,
fileName,
)
return err
},
},
{
Name: "remove",
Usage: "remove an existing template",
Action: func(c *cli.Context) error {
fmt.Println("removed task template: ", c.Args().First())
return nil
},
},
},
},
},
}
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}