github.com/apipluspower/gqlgen@v0.15.2/cmd/root.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/apipluspower/gqlgen/graphql"
    10  	"github.com/urfave/cli/v2"
    11  
    12  	// Required since otherwise dep will prune away these unused packages before codegen has a chance to run
    13  	_ "github.com/apipluspower/gqlgen/graphql/handler"
    14  	_ "github.com/apipluspower/gqlgen/handler"
    15  )
    16  
    17  func Execute() {
    18  	app := cli.NewApp()
    19  	app.Name = "gqlgen"
    20  	app.Usage = genCmd.Usage
    21  	app.Description = "This is a library for quickly creating strictly typed graphql servers in golang. See https://gqlgen.com/ for a getting started guide."
    22  	app.HideVersion = true
    23  	app.Flags = genCmd.Flags
    24  	app.Version = graphql.Version
    25  	app.Before = func(context *cli.Context) error {
    26  		if context.Bool("verbose") {
    27  			log.SetFlags(0)
    28  		} else {
    29  			log.SetOutput(ioutil.Discard)
    30  		}
    31  		return nil
    32  	}
    33  
    34  	app.Action = genCmd.Action
    35  	app.Commands = []*cli.Command{
    36  		genCmd,
    37  		initCmd,
    38  		versionCmd,
    39  	}
    40  
    41  	if err := app.Run(os.Args); err != nil {
    42  		fmt.Fprint(os.Stderr, err.Error()+"\n")
    43  		os.Exit(1)
    44  	}
    45  }