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

51 lines
1.2 KiB
Go

// Package commands contains the definition for all the commands present in
// Hasura CLI.
package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/spf13/cobra"
)
// ec is the Execution Context for the current run.
var ec *cli.ExecutionContext
// rootCmd is the main "hasura" command
var rootCmd = &cobra.Command{
Use: "hasura",
Short: "Hasura GraphQL Engine command line tool",
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
ec.Telemetry.Command = cmd.CommandPath()
},
}
func init() {
ec = cli.NewExecutionContext()
rootCmd.AddCommand(
NewInitCmd(ec),
NewConsoleCmd(ec),
NewMetadataCmd(ec),
NewMigrateCmd(ec),
NewVersionCmd(ec),
NewDocsCmd(ec),
)
f := rootCmd.PersistentFlags()
f.StringVar(&ec.LogLevel, "log-level", "INFO", "log level (DEBUG, INFO, WARN, ERROR, FATAL)")
f.StringVar(&ec.ExecutionDirectory, "project", "", "directory where commands are executed. (default: current dir)")
}
// Execute executes the command and returns the error
func Execute() error {
err := rootCmd.Execute()
if err != nil {
ec.Telemetry.IsError = true
}
ec.Telemetry.Beam()
if ec.Spinner != nil {
ec.Spinner.Stop()
}
return err
}