cli

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

README

Hasura GraphQL Engine CLI

GoDoc

Installation

Download GraphQL Engine CLI bundled with Hasura CLI
  • Linux/macOS
curl -L https://cli.hasura.io/install.sh | bash
Download using go get
go get github.com/hasura/graphql-engine/cli/cmd/hasura
Build from source
git clone https://github.com/hasura/graphql-engine
cd graphql-engine/cli
make deps
make build
# binaries will be in _output directory

Usage

hasura init --directory <my-project> --endpoint <graphql-endpoint> --admin-secret <admin-secret>
cd <my-project>
hasura console

Contributing

Checkout the contributing guide.

Documentation

Overview

Package cli and it's sub packages implements the command line tool for Hasura GraphQL Engine. The CLI operates on a directory, denoted by "ExecutionDirectory" in the "ExecutionContext" struct.

The ExecutionContext is passed to all the subcommands so that a singleton context is available for the execution. Logger and Spinner comes from the same context.

Index

Constants

View Source
const (
	// Name of the global configuration directory
	GlobalConfigDirName = ".hasura"
	// Name of the global configuration file
	GlobalConfigFileName = "config.json"

	// Name of the file to store last update check time
	LastUpdateCheckFileName = "last_update_check_at"
)

Other constants used in the package

View Source
const (
	StrTelemetryNotice = `` /* 214-byte string literal not displayed */

)

String constants

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionContext

type ExecutionContext struct {
	// CMDName is the name of CMD (os.Args[0]). To be filled in later to
	// correctly render example strings etc.
	CMDName string

	// ID is a unique ID for this Execution
	ID string

	// ServerUUID is the unique ID for the server this execution is contacting.
	ServerUUID string

	// Spinner is the global spinner object used to show progress across the cli.
	Spinner *spinner.Spinner
	// Logger is the global logger object to print logs.
	Logger *logrus.Logger

	// ExecutionDirectory is the directory in which command is being executed.
	ExecutionDirectory string
	// MigrationDir is the name of directory where migrations are stored.
	MigrationDir string
	// ConfigFile is the file where endpoint etc. are stored.
	ConfigFile string
	// MetadataFile (optional) is a yaml|json file where Hasura metadata is stored.
	MetadataFile []string

	// ServerConfig is the configuration object storing the endpoint and admin secret
	// information after reading from config file or env var.
	ServerConfig *ServerConfig

	// GlobalConfigDir is the ~/.hasura-graphql directory to store configuration
	// globally.
	GlobalConfigDir string
	// GlobalConfigFile is the file inside GlobalConfigDir where values are
	// stored.
	GlobalConfigFile string

	// GlobalConfig holds all the configuration options.
	GlobalConfig *GlobalConfig

	// IsStableRelease indicates if the CLI release is stable or not.
	IsStableRelease bool
	// Version indicates the version object
	Version *version.Version

	// Viper indicates the viper object for the execution
	Viper *viper.Viper

	// LogLevel indicates the logrus default logging level
	LogLevel string

	// NoColor indicates if the outputs shouldn't be colorized
	NoColor bool

	// Telemetry collects the telemetry data throughout the execution
	Telemetry *telemetry.Data

	// LastUpdateCheckFile is the file where the timestamp of last update check is stored
	LastUpdateCheckFile string

	// SkipUpdateCheck will skip the auto update check if set to true
	SkipUpdateCheck bool
}

ExecutionContext contains various contextual information required by the cli at various points of it's execution. Values are filled in by the initializers and passed on to each command. Commands can also fill in values to be used further down the line.

func NewExecutionContext

func NewExecutionContext() *ExecutionContext

NewExecutionContext returns a new instance of execution context

func (*ExecutionContext) GetExistingMetadataFile

func (ec *ExecutionContext) GetExistingMetadataFile() (string, error)

GetExistingMetadataFile returns the path to the default metadata file that also exists, json or yaml

func (*ExecutionContext) GetMetadataFilePath

func (ec *ExecutionContext) GetMetadataFilePath(format string) (string, error)

GetMetadataPath returns the file path based on the format.

func (*ExecutionContext) Prepare

func (ec *ExecutionContext) Prepare() error

Prepare as the name suggests, prepares the ExecutionContext ec by initializing most of the variables to sensible defaults, if it is not already set.

func (*ExecutionContext) Spin

func (ec *ExecutionContext) Spin(message string)

Spin stops any existing spinner and starts a new one with the given message.

func (*ExecutionContext) Validate

func (ec *ExecutionContext) Validate() error

Validate prepares the ExecutionContext ec and then validates the ExecutionDirectory to see if all the required files and directories are in place.

type GlobalConfig

type GlobalConfig struct {
	// UUID used for telemetry, generated on first run.
	UUID string `json:"uuid"`

	// Indicate if telemetry is enabled or not
	EnableTelemetry bool `json:"enable_telemetry"`

	// Indicates whether update notifications should be shown or not
	ShowUpdateNotification bool `json:"show_update_notification"`
}

GlobalConfig is the configuration object stored in the GlobalConfigFile.

type ServerConfig

type ServerConfig struct {
	// Endpoint for the GraphQL Engine
	Endpoint string
	// AdminSecret (optional) required to query the endpoint
	AdminSecret string

	ParsedEndpoint *url.URL
}

ServerConfig has the config values required to contact the server.

func (ServerConfig) MarshalJSON

func (s ServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON converts s to JSON

func (*ServerConfig) ParseEndpoint

func (s *ServerConfig) ParseEndpoint() error

ParseEndpoint ensures the endpoint is valid.

func (ServerConfig) UnmarshalJSON

func (s ServerConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON converts b to struct s

Directories

Path Synopsis
cmd
hasura command
Package main is the entrypoint for the command line executable.
Package main is the entrypoint for the command line executable.
Package commands contains the definition for all the commands present in Hasura CLI.
Package commands contains the definition for all the commands present in Hasura CLI.
Package migrate implements migrations on Hasura GraphQL Engine.
Package migrate implements migrations on Hasura GraphQL Engine.
api
cmd
Package util contains utility functions used by various commands.
Package util contains utility functions used by various commands.
Package version implements server, cli and console version handling.
Package version implements server, cli and console version handling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL