aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/cmd/root.go
blob: 519c2e1af51d9d0c318742f5ca0ff432bd61b369 (plain) (blame)
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
package cmd

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"

	"github.com/99designs/gqlgen/graphql"
	"github.com/99designs/gqlgen/internal/gopath"
	"github.com/urfave/cli"

	// Required since otherwise dep will prune away these unused packages before codegen has a chance to run
	_ "github.com/99designs/gqlgen/handler"
)

func Execute() {
	app := cli.NewApp()
	app.Name = "gqlgen"
	app.Usage = genCmd.Usage
	app.Description = "This is a library for quickly creating strictly typed graphql servers in golang. See https://gqlgen.com/ for a getting started guide."
	app.HideVersion = true
	app.Flags = genCmd.Flags
	app.Version = graphql.Version
	app.Before = func(context *cli.Context) error {
		pwd, err := os.Getwd()
		if err != nil {
			return fmt.Errorf("unable to determine current workding dir: %s\n", err.Error())
		}

		if !gopath.Contains(pwd) {
			return fmt.Errorf("gqlgen must be run from inside your $GOPATH\n")
		}
		if context.Bool("verbose") {
			log.SetFlags(0)
		} else {
			log.SetOutput(ioutil.Discard)
		}
		return nil
	}

	app.Action = genCmd.Action
	app.Commands = []cli.Command{
		genCmd,
		initCmd,
		versionCmd,
	}

	if err := app.Run(os.Args); err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)
	}
}