forked from Yamashou/gqlgenc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.48 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
package main
import (
"fmt"
"os"
"github.com/99designs/gqlgen/api"
"github.com/Yamashou/gqlgenc/clientgen"
"github.com/Yamashou/gqlgenc/clientgenv2"
"github.com/Yamashou/gqlgenc/config"
"github.com/Yamashou/gqlgenc/generator"
"github.com/urfave/cli/v2"
)
var generateCmd = &cli.Command{
Name: "generate",
Usage: "generate a graphql client based on schema",
Flags: []cli.Flag{
&cli.StringFlag{Name: "configdir, c", Usage: "the directory with configuration file", Value: "."},
},
Action: func(ctx *cli.Context) error {
configDir := ctx.String("configdir")
cfg, err := config.LoadConfigFromDefaultLocations(configDir)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err.Error())
os.Exit(2)
}
clientGen := api.AddPlugin(clientgen.New(cfg.Query, cfg.Client, cfg.Generate))
if cfg.Generate != nil {
if cfg.Generate.ClientV2 {
clientGen = api.AddPlugin(clientgenv2.New(cfg.Query, cfg.Client, cfg.Generate))
}
}
if err := generator.Generate(ctx.Context, cfg, clientGen); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err.Error())
os.Exit(4)
}
return nil
},
}
func main() {
app := cli.NewApp()
app.Name = "gqlgenc"
app.Description = "This is a library for quickly creating strictly typed graphql client in golang"
app.Usage = generateCmd.Usage
app.DefaultCommand = "generate"
app.Commands = []*cli.Command{
generateCmd,
}
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
}
}