~emersion/gqlclient

1ccb9b11f1ce7c332e6152eb3bb86ef175bde85f — Simon Ser 4 months ago d5fe5ef
cmd/gqlclientgen: default pkg name to dirname

Arguably more useful than "main".
1 files changed, 11 insertions(+), 2 deletions(-)

M cmd/gqlclientgen/main.go
M cmd/gqlclientgen/main.go => cmd/gqlclientgen/main.go +11 -2
@@ 5,6 5,7 @@ import (
	"fmt"
	"log"
	"os"
	"path/filepath"
	"sort"
	"strings"



@@ 23,7 24,7 @@ Options:
  -s <schema>   GraphQL schema, can be specified multiple times. Required.
  -q <query>    GraphQL query document, can be specified multiple times.
  -o <output>   Output filename for generated Go code. Required.
  -n <package>  Go package name, defaults to "main".
  -n <package>  Go package name, defaults to the dirname of the output file.
`

type stringSliceFlag []string


@@ 295,7 296,7 @@ func main() {
	var pkgName, outputFilename string
	flag.Var((*stringSliceFlag)(&schemaFilenames), "s", "schema filename")
	flag.Var((*stringSliceFlag)(&queryFilenames), "q", "query filename")
	flag.StringVar(&pkgName, "n", "main", "package name")
	flag.StringVar(&pkgName, "n", "", "package name")
	flag.StringVar(&outputFilename, "o", "", "output filename")
	flag.Usage = func() {
		fmt.Println(usage)


@@ 307,6 308,14 @@ func main() {
		os.Exit(1)
	}

	if pkgName == "" {
		abs, err := filepath.Abs(outputFilename)
		if err != nil {
			log.Fatalf("failed to get absolute output filename: %v", err)
		}
		pkgName = filepath.Base(filepath.Dir(abs))
	}

	var sources []*ast.Source
	for _, filename := range schemaFilenames {
		b, err := os.ReadFile(filename)