Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Note that genqlient now requires Go 1.23 or higher, and is tested through Go 1.2

### New features:

- Added `--version` flag to print version information including commit hash and build date

### Bug fixes:

- fixed minor typos and grammatical issues across the project
Expand Down
44 changes: 44 additions & 0 deletions generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"

"github.com/alexflint/go-arg"
Expand Down Expand Up @@ -59,6 +60,7 @@ func readConfigGenerateAndWrite(configFilename string) error {
type cliArgs struct {
ConfigFilename string `arg:"positional" placeholder:"CONFIG" default:"" help:"path to genqlient configuration (default: genqlient.yaml in current or any parent directory)"`
Init bool `arg:"--init" help:"write out and use a default config file"`
Version bool `arg:"--version" help:"print version information"`
}

func (cliArgs) Description() string {
Expand All @@ -68,6 +70,42 @@ See https://github.com/Khan/genqlient for full documentation.
`)
}

func printVersion() {
info, ok := debug.ReadBuildInfo()
if !ok {
fmt.Println("genqlient (version information not available)")
return
}

version := info.Main.Version
if version == "" || version == "(devel)" || strings.HasPrefix(version, "v0.0.0-") {
version = "dev"
}

var commit, buildDate string
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
commit = setting.Value
case "vcs.time":
buildDate = setting.Value
}
}

fmt.Print("genqlient " + version)
if commit != "" {
if len(commit) > 12 {
commit = commit[:12]
}
fmt.Printf(" (%s", commit)
if buildDate != "" {
fmt.Printf(", built %s", buildDate)
}
fmt.Print(")")
}
fmt.Println()
}

// Main is the command-line entrypoint to genqlient; it's equivalent to calling
//
// go run github.com/Khan/genqlient
Expand All @@ -83,6 +121,12 @@ func Main() {

var args cliArgs
arg.MustParse(&args)

if args.Version {
printVersion()
return
}

if args.Init {
filename := args.ConfigFilename
if filename == "" {
Expand Down
Loading