internals

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ArgumentFunctions contains functions to validate type.
	ArgumentFunctions = template.FuncMap{
		"returnsError": func(d ReturnType) bool {
			return d == ErrorReturn
		},
		"usesNoContext": func(d ContextType) bool {
			return d == NoContext
		},
		"usesGoogleContext": func(d ContextType) bool {
			return d == UseGoogleContext
		},
		"usesFauxContext": func(d ContextType) bool {
			return d == UseFauxContext
		},
		"hasArgumentStructExported": func(d ExportType) bool {
			return d == ExportedImport
		},
		"hasArgumentStructUnexported": func(d ExportType) bool {
			return d == UnExportedImport
		},
		"hasNoArgument": func(d ArgType) bool {
			return d == NoArgument
		},
		"hasContextArgument": func(d ArgType) bool {
			return d == WithContextArgument
		},
		"hasStringSliceArgument": func(d ArgType) bool {
			return d == WithStringSliceArgument
		},
		"hasStringArgument": func(d ArgType) bool {
			return d == WithStringArgument
		},
		"hasMapArgument": func(d ArgType) bool {
			return d == WithMapArgument
		},
		"hasStructArgument": func(d ArgType) bool {
			return d == WithStructArgument
		},
		"hasReadArgument": func(d ArgType) bool {
			return d == WithReaderArgument
		},
		"hasWriteArgument": func(d ArgType) bool {
			return d == WithWriteCloserArgument
		},
		"hasImportedArgument": func(d ArgType) bool {
			return d == WithImportedObjectArgument
		},
		"hasStringSliceArgumentWithWriter": func(d ArgType) bool {
			return d == WithStringSliceArgumentAndWriteCloserArgument
		},
		"hasStringArgumentWithWriter": func(d ArgType) bool {
			return d == WithStringArgumentAndWriteCloserArgument
		},
		"hasReadArgumentWithWriter": func(d ArgType) bool {
			return d == WithReaderAndWriteCloserArgument
		},
		"hasStructArgumentWithWriter": func(d ArgType) bool {
			return d == WithStructAndWriteCloserArgument
		},
		"hasMapArgumentWithWriter": func(d ArgType) bool {
			return d == WithMapAndWriteCloserArgument
		},
		"hasImportedArgumentWithWriter": func(d ArgType) bool {
			return d == WithImportedAndWriteCloserArgument
		},
	}
)

Functions

func FilterFlags

func FilterFlags(args []string) (flags, nonflags []string)

FilterFlags runs through a list of values and filters out values with `-` or `--` prefix has flags and others without `-`/`--` as non flags.

func StringToBoolSlice

func StringToBoolSlice(arg string) ([]bool, error)

StringToBoolSlice returns a bool slice from a comma seperated string.

func StringToFloat64Slice

func StringToFloat64Slice(arg string) ([]float64, error)

StringToFloat64Slice returns a int64 slice from a comma seperated string.

func StringToInt64Slice

func StringToInt64Slice(arg string) ([]int64, error)

StringToInt64Slice returns a int64 slice from a comma seperated string.

func StringToIntSlice

func StringToIntSlice(arg string) ([]int, error)

StringToIntSlice returns a int slice from a comma seperated string.

func StringToSlice

func StringToSlice(arg string) []string

StringToSlice turns a comma seperate string and returns a slice of all parts.

Types

type ArgType

type ArgType int

ArgType defines a int type represent the type of arguments a function receives.

const (
	NoArgument                                    ArgType = iota + 1 // is func()
	WithContextArgument                                              // is func(Context)
	WithStringArgument                                               // is func(string)
	WithStringSliceArgument                                          // is func(string)
	WithMapArgument                                                  // is func(map[string]interface{})
	WithStructArgument                                               // is func(Movie)
	WithImportedObjectArgument                                       // is func(types.IMovie)
	WithReaderArgument                                               // is func(io.Reader)
	WithWriteCloserArgument                                          // is func(io.WriteCloser)
	WithStringArgumentAndWriteCloserArgument                         // is func(string, io.WriteCloser)
	WithStringSliceArgumentAndWriteCloserArgument                    // is func(string, io.WriteCloser)
	WithStructAndWriteCloserArgument                                 // is func(Movie, io.WriteCloser)
	WithMapAndWriteCloserArgument                                    // is func(map[string]interface{}, io.WriteCloser)
	WithImportedAndWriteCloserArgument                               // is func(types.IMovie, io.WriteCloser)
	WithReaderAndWriteCloserArgument                                 // is func(io.Reader, io.WriteCloser)
	WithUnknownArgument
)

const for input state.

func (ArgType) Int

func (f ArgType) Int() int

Int returns the real int value of the typr.

type ContextType

type ContextType int

ContextType defines a int type represent the type of context argument a function receives.

const (
	NoContext ContextType = iota + 1
	UseGoogleContext
	UseFauxContext
	UseUnknownContext
)

consts for use or absence of context.

func (ContextType) Int

func (f ContextType) Int() int

Int returns the real int value of the typr.

type ExportType

type ExportType int

ExportType defines a int type represent the export state of a function.

const (
	UnExportedImport ExportType = iota + 1
	ExportedImport
)

const for type export state.

func (ExportType) Int

func (f ExportType) Int() int

Int returns the real int value of the typr.

type Flag

type Flag struct {
	EnvVar string
	Name   string
	Desc   string
	Type   FlagType
}

Flag contains details related to a provided flag.

func (Flag) FromEnv

func (f Flag) FromEnv() (string, bool)

FromEnv attempts to pull giving Flag value from environment.

func (Flag) FromList

func (f Flag) FromList(args []string) (string, bool)

FromList attempts to pull giving Flag value from list.

func (Flag) UsesEnv

func (f Flag) UsesEnv() bool

UsesEnv returns true/false if the flags can use an environment variable name.

type FlagType

type FlagType int

FlagType defines a int type represent the type of flag a function wants.

const (
	BadFlag FlagType = iota
	IntFlag
	Int64Flag
	UintFlag
	Uint64Flag
	StringFlag
	BoolFlag
	TBoolFlag
	DurationFlag
	Float64Flag
	IntSliceFlag
	Int64SliceFlag
	StringSliceFlag
	BoolSliceFlag
	AnyTypeFlag
	Float64SliceFlag
)

const of flag types.

func GetFlag

func GetFlag(name string) FlagType

GetFlag returns a FlagType for the giving name.

func (FlagType) Int

func (f FlagType) Int() int

Int returns the Flag type back as it's int value.

func (FlagType) String

func (f FlagType) String() string

FlagType returns associated type.

type Flags

type Flags []Flag

Flags defines a type of Flag slice which exposes a method that attempts to load values of flags either from env or from a provided flag list of `key=value` value pairs.

func (Flags) Load

func (f Flags) Load(args []string) (map[string]interface{}, error)

Load attempts to load flag values from slice list of `key=value` pairs else if flag supports environment variables, will attempt to load throug that instead. It returns a map of all loaded values and an error.

type Function

type Function struct {
	Context               ContextType
	Type                  ArgType
	Return                ReturnType
	StructExported        ExportType
	Exported              bool
	Default               bool
	RealName              string
	Name                  string
	From                  string
	Synopses              string
	Source                string
	Description           string
	Package               string
	PackagePath           string
	PackageFile           string
	PackageFileName       string
	HelpMessage           string
	HelpMessageWithSource string
	Depends               []string
	Flags                 Flags
	Imports               VarMeta
	ContextImport         VarMeta
}

Function defines a struct type that represent meta details of a giving function.

type PackageFunctions

type PackageFunctions struct {
	Name       string
	Hash       string
	Path       string
	Desc       string
	FilePath   string
	BinaryName string
	MaxNameLen int
	List       []Function
}

PackageFunctions holds a package level function with it's path and name.

func (PackageFunctions) Default

func (pn PackageFunctions) Default() []Function

Default returns the function set has default for when the execution is called.

func (PackageFunctions) HasFauxImports

func (pn PackageFunctions) HasFauxImports() bool

HasFauxImports returns true/false if any part of the function uses faux context.

func (PackageFunctions) HasGoogleImports

func (pn PackageFunctions) HasGoogleImports() bool

HasGoogleImports returns true/false if any part of the function uses google context.

func (PackageFunctions) Imports

func (pn PackageFunctions) Imports() map[string]string

Imports returns a map of all import paths for giving package functions.

func (PackageFunctions) SpaceFor

func (pn PackageFunctions) SpaceFor(name string) string

SpaceFor returns space value for a giving name.

type ReturnType

type ReturnType int

ReturnType defines a int type represent the type of return a function provides.

const (
	NoReturn ReturnType = iota + 1
	ErrorReturn
	UnknownErrorReturn
)

const for return state.

func (ReturnType) Int

func (f ReturnType) Int() int

Int returns the real int value of the typr.

type ShogunFunc

type ShogunFunc struct {
	NS       string      `json:"ns"`
	Type     ArgType     `json:"type"`
	Return   ReturnType  `json:"return"`
	Context  ContextType `json:"context"`
	Name     string      `json:"name"`
	Source   string      `json:"source"`
	Flags    Flags       `json:"flags"`
	Function interface{} `json:"-"`
}

ShogunFunc defines a type which contains a function definition details.

type VarMeta

type VarMeta struct {
	Import     string
	ImportNick string
	Type       string
	TypeAddr   string
	Exported   ExportType
}

VarMeta defines a struct to hold object details.

Directories

Path Synopsis
Package kensho provides a series of tests case which can be used to validate that a giving generated shogun package meet it's design and expected operation.
Package kensho provides a series of tests case which can be used to validate that a giving generated shogun package meet it's design and expected operation.

Jump to

Keyboard shortcuts

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