-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (92 loc) · 2.54 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
92
93
94
package main
import (
"github.com/urfave/cli/v2"
"log"
"os"
"para/script"
"sort"
)
func main() {
app := &cli.App{
Name: "ParaCLI",
Usage: "ParaSnack模板生成脚手架!",
Version: "0.1.8",
UseShortOptionHandling: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "new",
Aliases: []string{"n"},
Usage: "生成新的Snack模板.",
},
&cli.StringFlag{
Name: "get",
Aliases: []string{"g"},
Usage: "拉取仓库组件到本地Snack工程下的Components目录.",
},
&cli.StringFlag{
Name: "upload",
Aliases: []string{"up"},
Usage: "上传组件到仓库.",
},
},
Commands: []*cli.Command{
{
Name: "new",
Aliases: []string{"n"},
Usage: "生成新的Snack模板. p 指定拉取组件的路径.",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "sync", Aliases: []string{"s"}},
&cli.StringFlag{Name: "path", Aliases: []string{"p"}},
&cli.StringFlag{Name: "remote", Aliases: []string{"r"}},
&cli.StringFlag{Name: "ppath", Aliases: []string{"pp"}},
},
Action: func(cCtx *cli.Context) error {
err := script.Generate(cCtx)
if err != nil {
return err
}
return nil
},
},
{
Name: "get",
Aliases: []string{"g"},
Usage: "拉取仓库组件到本地Snack工程下的Components目录. -s 是否同步创建Snack组件文件并引用. -r 指定生成Snack组件文件的地址. -p 指定拉取组件的路径 -pp 指定拉取组件的页面.",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "sync", Aliases: []string{"s"}},
&cli.StringFlag{Name: "path", Aliases: []string{"p"}},
&cli.StringFlag{Name: "remote", Aliases: []string{"r"}},
&cli.StringFlag{Name: "ppath", Aliases: []string{"pp"}},
},
Action: func(cCtx *cli.Context) error {
//fmt.Println("sync:", cCtx.Bool("sync"))
//fmt.Println("path:", cCtx.String("path"))
//fmt.Println("remote:", cCtx.String("remote"))
//fmt.Println("name:", cCtx.Args().First())
err := script.Download(cCtx)
if err != nil {
return err
}
return nil
},
},
{
Name: "upload",
Aliases: []string{"up"},
Usage: "提交组件到仓库. -p 文件夹路径.",
Action: func(cCtx *cli.Context) error {
err := script.Upload(cCtx)
if err != nil {
return err
}
return nil
},
},
},
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}