-
Notifications
You must be signed in to change notification settings - Fork 67
/
main.go
61 lines (52 loc) · 1.32 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
package main
import (
"fmt"
"os"
"github.com/Yamashou/gqlgenc/config"
"github.com/Yamashou/gqlgenc/generator"
"github.com/urfave/cli/v2"
)
const version = "0.27.3"
var versionCmd = &cli.Command{
Name: "version",
Usage: "print the version",
Action: func(ctx *cli.Context) error {
fmt.Println(version)
return nil
},
}
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)
}
if err := generator.Generate(ctx.Context, cfg); 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{
versionCmd,
generateCmd,
}
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
}
}