graphql-engine/cli/commands/version.go
2019-01-28 19:25:28 +05:30

33 lines
847 B
Go

package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// NewVersionCmd returns the version command
func NewVersionCmd(ec *cli.ExecutionContext) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the CLI version",
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = viper.New()
return ec.Prepare()
},
RunE: func(cmd *cobra.Command, args []string) error {
ec.Logger.WithField("version", ec.Version.GetCLIVersion()).Info("hasura cli")
err := ec.Validate()
if err == nil {
ec.Logger.
WithField("endpoint", ec.Config.Endpoint).
WithField("version", ec.Version.GetServerVersion()).
Info("hasura graphql engine")
}
return nil
},
}
return versionCmd
}