This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.go
156 lines (145 loc) · 3.82 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"errors"
"os"
"github.com/Jumpscale/go-raml/commands"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
//Version define software version
var Version = "0.1-Dev"
//ApplicationName is the name of the application
var ApplicationName = "RAML code generation toolset"
var (
serverCommand = &commands.ServerCommand{}
clientCommand = &commands.ClientCommand{}
specCommand = &commands.SpecCommand{}
)
func main() {
app := cli.NewApp()
app.Name = ApplicationName
app.Version = Version
app.Usage = "Using a RAML specification, generate server and client code or a RAML specification from go code."
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
var debugLogging bool
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
Destination: &debugLogging,
},
}
app.Before = func(c *cli.Context) error {
if debugLogging {
log.SetLevel(log.DebugLevel)
log.Debug("Debug logging enabled")
log.Debug(ApplicationName, "-", Version)
}
return nil
}
app.Commands = []cli.Command{
{
Name: "server",
Usage: "Generate a go server according to a RAML specification",
Flags: []cli.Flag{
cli.StringFlag{
Name: "language, l",
Value: "go",
Usage: "Language to construct a server for",
Destination: &serverCommand.Language,
},
cli.StringFlag{
Name: "dir",
Value: ".",
Usage: "target directory",
Destination: &serverCommand.Dir,
},
cli.StringFlag{
Name: "ramlfile",
Value: ".",
Usage: "Source raml file",
Destination: &serverCommand.RamlFile,
},
cli.StringFlag{
Name: "package",
Value: "main",
Usage: "package name",
Destination: &serverCommand.PackageName,
},
cli.BoolFlag{
Name: "no-main",
Usage: "Do not generate a main.go file",
Destination: &serverCommand.NoMainGeneration,
},
cli.BoolFlag{
Name: "no-apidocs",
Usage: "Do not generate API Docs in /apidocs/ endpoint",
Destination: &serverCommand.NoAPIDocs,
},
cli.StringFlag{
Name: "import-path",
Value: "examples.com/ramlcode",
Usage: "import path of the generated code",
Destination: &serverCommand.ImportPath,
},
},
Action: func(c *cli.Context) {
if err := serverCommand.Execute(); err != nil {
log.Error(err)
}
},
},
{
Name: "client",
Usage: "Create a client for a RAML specification",
Flags: []cli.Flag{
cli.StringFlag{
Name: "language, l",
Value: "go",
Usage: "Language to construct a client for",
Destination: &clientCommand.Language,
},
cli.StringFlag{
Name: "dir",
Value: ".",
Usage: "target directory",
Destination: &clientCommand.Dir,
},
cli.StringFlag{
Name: "ramlfile",
Value: ".",
Usage: "Source raml file",
Destination: &clientCommand.RamlFile,
},
cli.StringFlag{
Name: "package",
Value: "client",
Usage: "package name",
Destination: &clientCommand.PackageName,
},
cli.StringFlag{
Name: "import-path",
Value: "examples.com/client",
Usage: "import path of the generated code",
Destination: &clientCommand.ImportPath,
},
},
Action: func(c *cli.Context) {
if err := clientCommand.Execute(); err != nil {
log.Error(err)
}
},
}, {
Name: "spec",
Usage: "Generate a RAML specification from a go server",
Action: func(c *cli.Context) {
err := errors.New("Not implemented, check the roadmap")
log.Error(err)
},
},
}
app.Action = func(c *cli.Context) {
cli.ShowAppHelp(c)
}
app.Run(os.Args)
}