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
12 changes: 11 additions & 1 deletion cmd/graphql-schema-picker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import (
"github.com/kevinmichaelchen/graphql-schema-picker/internal/cli"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
cli.Main()
cli.Main(cli.LDFlags{
Version: version,
Commit: commit,
Date: date,
})
}
13 changes: 12 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ var rootCmd = &cobra.Command{
}

var (
ldFlags LDFlags
sdlFile string
debug bool
dryRun bool
desiredDefinitions []string
output string
)

// LDFlags contain fields that get linked and compiled into the final binary
// program at build time.
type LDFlags struct {
Version string
Commit string
Date string
}

func init() {
rootCmd.AddCommand(pick)
rootCmd.AddCommand(versionCmd)

rootCmd.PersistentFlags().StringVarP(&sdlFile, "sdl-file", "f", "", "path to an SDL file")
rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "", false, "verbose debug logging")
Expand All @@ -38,7 +48,8 @@ func init() {
pick.Flags().StringVarP(&output, "output", "o", "", "where the resulting schema/SDL file is written")
}

func Main() {
func Main(ldf LDFlags) {
ldFlags = ldf
if err := rootCmd.Execute(); err != nil {
log.Error("execution failed", "err", err)
os.Exit(1)
Expand Down
17 changes: 17 additions & 0 deletions internal/cli/cli_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cli

import (
"fmt"
"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints CLI version info",
Long: `Prints CLI version info`,
Run: fnVersion,
}

func fnVersion(cmd *cobra.Command, args []string) {
fmt.Printf("version %s\n", ldFlags.Version)
}