Skip to content

Commit

Permalink
support a version subcommand too, fix behavior on no args
Browse files Browse the repository at this point in the history
  • Loading branch information
benweint committed May 29, 2024
1 parent 29be52b commit bd15c08
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions pkg/commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ import (
"github.com/alecthomas/kong"
)

// version string will be injected by automation
var version string = "unknown"

type CLI struct {
Ls LsCmd `cmd:"" aliases:"list" help:"List types, fields, or directives in a GraphQL SDL document."`
Json JsonCmd `cmd:"" help:"Return a JSON representation of a GraphQL SDL document."`
Introspection IntrospectionCmd `cmd:"" help:"Interact with a GraphQL introspection endpoint over HTTP."`
Viz VizCmd `cmd:"" help:"Visualize a GraphQL schema using GraphViz."`
Merge MergeCmd `cmd:"" help:"Merge multiple GraphQL SDL documents into a single one."`
Version versionFlag `help:"Print version and exit."`
}

type versionFlag bool

func (f versionFlag) BeforeReset(ctx *kong.Context) error {
_, _ = ctx.Stdout.Write([]byte(version + "\n"))
ctx.Kong.Exit(0)
return nil
VersionFlag versionFlag `name:"version" help:"Print version and exit."`

Check failure on line 15 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / lint

undefined: versionFlag

Check failure on line 15 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / lint

undefined: versionFlag

Check failure on line 15 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / build

undefined: versionFlag

Check failure on line 15 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / build

undefined: versionFlag
Version VersionCmd `cmd:"" help:"Print the version of gquil and exit."`

Check failure on line 16 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / lint

undefined: VersionCmd) (typecheck)

Check failure on line 16 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / lint

undefined: VersionCmd (typecheck)

Check failure on line 16 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / build

undefined: VersionCmd

Check failure on line 16 in pkg/commands/cli.go

View workflow job for this annotation

GitHub Actions / build

undefined: VersionCmd
}

func MakeParser(opts ...kong.Option) (*kong.Kong, error) {
Expand All @@ -47,7 +37,7 @@ func massageArgs(args []string) []string {
args = args[1:]

if len(args) == 0 {
return []string{args[0], "--help"}
return []string{"--help"}
}

if args[0] == "help" {
Expand Down

0 comments on commit bd15c08

Please sign in to comment.