-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcli.go
141 lines (119 loc) · 2.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"os"
"time"
"github.com/champii/og/lib/common"
"github.com/urfave/cli"
)
func parseArgs(done func(*common.OgConfig)) {
cli_ := setupCli()
cli_.Action = func(c *cli.Context) error {
options := common.OgConfig{
Blocks: c.Bool("b"),
Dirty: c.Bool("d"),
Print: c.Bool("p"),
Ast: c.Bool("a"),
SimpleAst: c.Bool("s"),
Quiet: c.Bool("q"),
Workers: c.Int("w"),
OutPath: c.String("o"),
Interpreter: c.Bool("i"),
NoBuild: c.Bool("n"),
Run: c.Bool("r"),
Force: c.Bool("f"),
Paths: []string(c.Args()),
}
done(&options)
return nil
}
cli_.Run(os.Args)
}
func setupCli() *cli.App {
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
VERSION:
{{.Version}}
USAGE:
{{if .VisibleFlags}}{{.HelpName}} [options] [folders...|files...]
If a Print argument (-p, -b, -d, -a) is given, no write on disk is done.
If run without files, it will compile and build '.'{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
{{end}}
`
cli.VersionFlag = cli.BoolFlag{
Name: "v, version",
Usage: "Print version",
}
cli.HelpFlag = cli.BoolFlag{
Name: "h, help",
Usage: "Print help",
}
app := cli.NewApp()
app.Name = "Oglang"
app.Version = "v0.7.2"
app.Compiled = time.Now()
app.Usage = "Golang on steroids"
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "r, run",
Usage: "Run the binary",
},
cli.StringFlag{
Name: "o, out",
Usage: "Output destination `directory`.",
Value: "./",
},
cli.IntFlag{
Name: "w, workers",
Usage: "Set the number of `jobs`",
Value: 8,
},
cli.BoolFlag{
Name: "f, force",
Usage: "Force the compilation even if no changes",
},
cli.BoolFlag{
Name: "p, print",
Usage: "Print the file",
},
cli.BoolFlag{
Name: "d, dirty",
Usage: "Print the file before going through 'go fmt'",
},
cli.BoolFlag{
Name: "b, blocks",
Usage: "Print the file after it goes to preprocessor.",
},
cli.BoolFlag{
Name: "a, ast",
Usage: "Print the generated AST",
},
cli.BoolFlag{
Name: "s, simple-ast",
Usage: "Print a simple AST instead with only terminals",
},
cli.BoolFlag{
Name: "i, interpreter",
Usage: "Run a small interpreter (ALPHA)",
},
cli.BoolFlag{
Name: "q, quiet",
Usage: "Hide the progress output",
},
cli.BoolFlag{
Name: "n, no-build",
Usage: "Don't run 'go build'",
},
}
app.UsageText = "og [options] [folders|files]"
return app
}