forked from americanas-tech/restQL-cli
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
103 lines (95 loc) · 2.7 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
package main
import (
"fmt"
"github.com/americanas-tech/restQL-cli/restql"
"github.com/urfave/cli/v2"
"os"
)
const defaultRestqlVersion = "v6.2.0"
func main() {
app := newApp()
if err := app.Run(os.Args); err != nil {
fmt.Printf("[ERROR] failed to initialize RestQL CLI : %v", err)
os.Exit(1)
}
}
func newApp() *cli.App {
return &cli.App{
Name: "restql",
Usage: "Manage the development and building of plugins within RestQL",
Commands: []*cli.Command{
{
Name: "build",
Usage: "Builds custom binaries for RestQL with the given plugins",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "restql-replacement",
Value: "",
Usage: "Set the path to the local restQL codebase",
},
&cli.StringSliceFlag{
Name: "with",
Aliases: []string{"w"},
Required: true,
Usage: "Specify the Go Module name of the plugin, can optionally set the version and a replace path: github.com/user/plugin[@version][=../replace/path]",
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: "./",
Usage: "Set the location where the final binary will be placed",
},
},
Action: func(ctx *cli.Context) error {
withPlugins := ctx.StringSlice("with")
output := ctx.String("output")
restqlReplacement := ctx.String("restql-replacement")
restqlVersion := ctx.Args().Get(0)
if restqlVersion == "" {
restqlVersion = defaultRestqlVersion
}
return restql.Build(withPlugins, restqlVersion, restqlReplacement, output)
},
},
{
Name: "run",
Usage: "Run RestQL with the plugin at working directory",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "restql-replacement",
Value: "",
Usage: "Set the path to the local restQL codebase",
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: "./restql.yml",
Usage: "Set the location where the YAML configuration file is placed",
},
&cli.StringFlag{
Name: "plugin",
Aliases: []string{"p"},
Value: "./",
Usage: "Set the location of the plugin in development",
},
&cli.BoolFlag{
Name: "race",
Value: false,
Usage: "Enable Go race detection",
},
},
Action: func(ctx *cli.Context) error {
restqlReplacement := ctx.String("restql-replacement")
config := ctx.String("config")
pluginLocation := ctx.String("plugin")
race := ctx.Bool("race")
restqlVersion := ctx.Args().Get(0)
if restqlVersion == "" {
restqlVersion = defaultRestqlVersion
}
return restql.Run(restqlReplacement, restqlVersion, config, pluginLocation, race)
},
},
},
}
}