cmd

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheTimeout time.Duration = -10 * time.Minute
)

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FieldCommandArgName

func FieldCommandArgName(f FieldCommandArgument) string

func FieldCommandArgType

func FieldCommandArgType(f FieldCommandArgument) string

func NewCompletionCommand

func NewCompletionCommand(config CompletionCommandConfig) *cobra.Command

func NewFieldsCommand

func NewFieldsCommand(schema introspection.Schema) *cobra.Command

fieldsCmd represents the fields command

func NewRawCommand

func NewRawCommand(config RawCommandConfig) *cobra.Command

rawCmd represents the raw command

func NewRootCommand

func NewRootCommand(args []string) *cobra.Command

NewRootCommand creates root command a base command for gql

func Peek

func Peek(
	cargs []string,
	endpoint *string,
	header Header,
	flagset *pflag.FlagSet) []string

find GraphQL endpoint option and query path

func Set

func Set(cmd *cobra.Command, f FieldCommandArgument)

Types

type ArgsCommandConfig

type ArgsCommandConfig struct {
	Config
	Schema ArgsSchema
}

type ArgsSchema

type ArgsSchema interface {
	// FieldForPath returns field for object for path, or false
	// if not found
	FieldForPath([]string) (introspection.Field, bool)
}

ArgsSchema defines interface that must be implemented by schema for args command

type Command

type Command struct {
	*cobra.Command
	Config
}

func NewArgsCommand

func NewArgsCommand(config ArgsCommandConfig) *Command

argsCmd represents the args command

type CommandBuilder

type CommandBuilder interface {
	New([]string) *cobra.Command
}

type CommandBuilderFunc

type CommandBuilderFunc func([]string) *cobra.Command

func (CommandBuilderFunc) New

func (d CommandBuilderFunc) New(args []string) *cobra.Command

type CompletionCommandConfig

type CompletionCommandConfig struct {
	Config
	CommandBuilder
}

type Config

type Config struct {
	In       io.Reader
	Out      io.Writer
	Err      io.Writer
	ExitFunc func(int)
}

func (Config) Error

func (c Config) Error() io.Writer

func (Config) Exit

func (c Config) Exit(code int)

func (Config) Input

func (c Config) Input() io.Reader

func (Config) Output

func (c Config) Output() io.Writer

type FieldCommand

type FieldCommand struct {
	*cobra.Command
	Field    introspection.Field
	Schema   introspection.Schema
	Args     []FieldCommandArgument
	MaxDepth int
	Fields   []string
}

func NewFieldCommand

func NewFieldCommand(
	field introspection.Field,
	schema introspection.Schema,
	RunE func(*cobra.Command, []string) error,
	PreRun func(*cobra.Command, []string),
) *FieldCommand

func (*FieldCommand) ArgsString

func (f *FieldCommand) ArgsString() string

func (*FieldCommand) BuildQuery

func (f *FieldCommand) BuildQuery() string

type FieldCommandArgument

type FieldCommandArgument interface {
	FieldCommandValue
	// argument value
	Value() interface{}
	// argument name
	Name() string
}

func GetFieldArguments

func GetFieldArguments(field introspection.Field) []FieldCommandArgument

type FieldCommandBooleanArgument

type FieldCommandBooleanArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandBooleanArgument) Name

func (*FieldCommandBooleanArgument) String

func (f *FieldCommandBooleanArgument) String() string

func (*FieldCommandBooleanArgument) Type

func (*FieldCommandBooleanArgument) Value

func (f *FieldCommandBooleanArgument) Value() interface{}

type FieldCommandCustomScalarArgument

type FieldCommandCustomScalarArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandCustomScalarArgument) Name

func (*FieldCommandCustomScalarArgument) String

func (*FieldCommandCustomScalarArgument) Type

func (*FieldCommandCustomScalarArgument) Value

func (f *FieldCommandCustomScalarArgument) Value() interface{}

type FieldCommandEnumArgument

type FieldCommandEnumArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandEnumArgument) Name

func (f *FieldCommandEnumArgument) Name() string

func (*FieldCommandEnumArgument) String

func (f *FieldCommandEnumArgument) String() string

func (*FieldCommandEnumArgument) Type

func (f *FieldCommandEnumArgument) Type() string

func (*FieldCommandEnumArgument) Value

func (f *FieldCommandEnumArgument) Value() interface{}

type FieldCommandFloatArgument

type FieldCommandFloatArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandFloatArgument) Name

func (*FieldCommandFloatArgument) String

func (f *FieldCommandFloatArgument) String() string

func (*FieldCommandFloatArgument) Type

func (*FieldCommandFloatArgument) Value

func (f *FieldCommandFloatArgument) Value() interface{}

type FieldCommandIDArgument

type FieldCommandIDArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandIDArgument) Name

func (f *FieldCommandIDArgument) Name() string

func (*FieldCommandIDArgument) String

func (f *FieldCommandIDArgument) String() string

func (*FieldCommandIDArgument) Type

func (f *FieldCommandIDArgument) Type() string

func (*FieldCommandIDArgument) Value

func (f *FieldCommandIDArgument) Value() interface{}

type FieldCommandInputArgument

type FieldCommandInputArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandInputArgument) Name

func (*FieldCommandInputArgument) String

func (f *FieldCommandInputArgument) String() string

func (*FieldCommandInputArgument) Type

func (*FieldCommandInputArgument) Value

func (f *FieldCommandInputArgument) Value() interface{}

type FieldCommandIntArgument

type FieldCommandIntArgument struct {
	// contains filtered or unexported fields
}

represnets GraphQL field argument of type Int

func (*FieldCommandIntArgument) Name

func (f *FieldCommandIntArgument) Name() string

func (*FieldCommandIntArgument) String

func (f *FieldCommandIntArgument) String() string

func (*FieldCommandIntArgument) Type

func (f *FieldCommandIntArgument) Type() string

func (*FieldCommandIntArgument) Value

func (f *FieldCommandIntArgument) Value() interface{}

type FieldCommandListArgument

type FieldCommandListArgument struct {
	FieldCommandArgument
	// contains filtered or unexported fields
}

func (*FieldCommandListArgument) String

func (f *FieldCommandListArgument) String() string

func (*FieldCommandListArgument) Type

func (f *FieldCommandListArgument) Type() string

func (*FieldCommandListArgument) Value

func (f *FieldCommandListArgument) Value() interface{}

type FieldCommandNonNullArgument

type FieldCommandNonNullArgument struct {
	FieldCommandArgument
}

func (*FieldCommandNonNullArgument) Type

func (*FieldCommandNonNullArgument) Value

func (f *FieldCommandNonNullArgument) Value() interface{}

type FieldCommandStringArgument

type FieldCommandStringArgument struct {
	// contains filtered or unexported fields
}

func (*FieldCommandStringArgument) Name

func (*FieldCommandStringArgument) String

func (f *FieldCommandStringArgument) String() string

func (*FieldCommandStringArgument) Type

func (*FieldCommandStringArgument) Value

func (f *FieldCommandStringArgument) Value() interface{}

type FieldCommandValue

type FieldCommandValue interface {
	// GraphQL-like string of value
	String() string
	// return GraphQL type name of the argument
	Type() string
}

type GraphQLCommand

type GraphQLCommand struct {
	Config       GraphQLCommandConfig
	FieldCommand *FieldCommand
	QueryBuilder *QueryBuilder
}

func NewGraphQLCommand

func NewGraphQLCommand(config GraphQLCommandConfig) GraphQLCommand

func (*GraphQLCommand) BuildSubCommands

func (g *GraphQLCommand) BuildSubCommands() error

func (*GraphQLCommand) FieldPreRun

func (g *GraphQLCommand) FieldPreRun(c *cobra.Command, args []string)

appends field query parent to a query

func (*GraphQLCommand) RunE

func (g *GraphQLCommand) RunE(c *cobra.Command, args []string) error

run command

type GraphQLCommandConfig

type GraphQLCommandConfig struct {
	Config
	// requied: name of the field this command resolves
	Field introspection.Field
	// required: query builder
	QueryBuilder *QueryBuilder
	// optional: path requested from this field
	Path []string
	// required: schema executed by command
	Schema introspection.Schema
}

type GraphQLCommandType

type GraphQLCommandType struct {
	Description string
	Fields      map[string]*FieldCommand
}

type GraphQLRootCommands

type GraphQLRootCommands struct {
	Config       GraphQLRootConfig
	Query        GraphQLCommand
	Mutation     GraphQLCommand
	Subscription GraphQLCommand
	Schema       introspection.Schema
	QueryBuilder *QueryBuilder
}

func DefaultRootCommands

func DefaultRootCommands() GraphQLRootCommands

func NewGraphQLRootCommands

func NewGraphQLRootCommands(config GraphQLRootConfig) (GraphQLRootCommands, error)

func (*GraphQLRootCommands) RunE

func (g *GraphQLRootCommands) RunE(c *cobra.Command, args []string) error

common run function for all GraphQL commands

type GraphQLRootConfig

type GraphQLRootConfig struct {
	Config
	// required: remote graphql endpoint
	Endpoint string
	// any additional headers that should
	// be attached to the request
	Header Header
	// ignore local schema data and use upstream
	// endpoint, optional
	ForceRemote bool
	// optional: query builder used by command
	QueryBuilder *QueryBuilder
	// required: path being resolved by a command
	Path []string
	// optional: local schema
	Schema *graphql.Schema
}

all commands on graphql start here

type GraphQLTypeCommandMap

type GraphQLTypeCommandMap map[string]GraphQLCommandType
type Header map[string]string

func (Header) Set

func (h Header) Set(val string) error

func (Header) String

func (h Header) String() string

func (Header) Type

func (h Header) Type() string

type IntrospectionCommand

type IntrospectionCommand struct {
	*cobra.Command
	GraphQLRootCommands
	Config IntrospectionCommandConfig
}

type IntrospectionCommandConfig

type IntrospectionCommandConfig struct {
	Path     []string
	Endpoint string
	Header   Header
}

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

func (*QueryBuilder) Query

func (qb *QueryBuilder) Query() string

func (*QueryBuilder) Set

func (qb *QueryBuilder) Set(name string, value interface{})

func (*QueryBuilder) Variables

func (qb *QueryBuilder) Variables() map[string]interface{}

func (*QueryBuilder) Wrap

func (qb *QueryBuilder) Wrap(name string, extra ...string)

type RawCommandConfig

type RawCommandConfig struct {
	Config
}

type Setter

type Setter interface {
	Set(*cobra.Command, FieldCommandArgument)
}

type Variables

type Variables map[string]interface{}

func (Variables) Set

func (v Variables) Set(val string) error

func (Variables) String

func (v Variables) String() string

func (Variables) Type

func (v Variables) Type() string

func (Variables) Unflatten

func (v Variables) Unflatten() map[string]interface{}

Jump to

Keyboard shortcuts

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