prototype

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2018 License: Apache-2.0 Imports: 21 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// DefaultAPIVersion is the default api version for a prototype.
	DefaultAPIVersion = "0.0.1"

	// DefaultKind is the default kind for a prototype.
	DefaultKind = "ksonnet.io/prototype"
)

Variables

View Source
var (
	// DefaultBuilder is a builder that will build a prototype from a source string.
	DefaultBuilder = JsonnetParse
)

Functions

func BindFlags added in v0.12.0

func BindFlags(p *Prototype) (fs *pflag.FlagSet, err error)

BindFlags creates a flag set using a prototype's parameters.

func ExtractParameters added in v0.12.0

func ExtractParameters(fs afero.Fs, p *Prototype, flags *pflag.FlagSet) (map[string]string, error)

ExtractParameters extracts prototypes parameters from flags.

Types

type Builder added in v0.11.0

type Builder func(source string) (*Prototype, error)

Builder builds a prototype from a source string.

type FlagDefinitionError added in v0.12.0

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

FlagDefinitionError is an error returned when a flag definition fails.

func (*FlagDefinitionError) Error added in v0.12.0

func (e *FlagDefinitionError) Error() string

type Index

type Index interface {
	List() (Prototypes, error)
	SearchNames(query string, opts SearchOptions) (Prototypes, error)
}

Index represents a queryable index of prototype specifications.

func NewIndex

func NewIndex(prototypes []*Prototype, builder Builder) (Index, error)

NewIndex constructs an index of prototype specifications from a list.

type ParamSchema

type ParamSchema struct {
	Name        string    `json:"name"`
	Alias       *string   `json:"alias"` // Optional.
	Description string    `json:"description"`
	Default     *string   `json:"default"` // `nil` only if the parameter is optional.
	Type        ParamType `json:"type"`
}

ParamSchema is the JSON-serializable representation of a parameter provided to a prototype.

func (*ParamSchema) Quote

func (ps *ParamSchema) Quote(value string) (string, error)

Quote will parse a prototype parameter and quote it appropriately, so that it shows up correctly in Jsonnet source code. For example, `--image nginx` would likely need to show up as `"nginx"` in Jsonnet source.

type ParamSchemas

type ParamSchemas []*ParamSchema

ParamSchemas is a slice of `ParamSchema`

func (ParamSchemas) PrettyString

func (ps ParamSchemas) PrettyString(prefix string) string

PrettyString creates a prettified string representing a collection of parameters.

type ParamType

type ParamType string

ParamType represents a type constraint for a prototype parameter (e.g., it must be a number).

const (
	// Number represents a prototype parameter that must be a number.
	Number ParamType = "number"

	// String represents a prototype parameter that must be a string.
	String ParamType = "string"

	// NumberOrString represents a prototype parameter that must be either a
	// number or a string.
	NumberOrString ParamType = "numberOrString"

	// Object represents a prototype parameter that must be an object.
	Object ParamType = "object"

	// Array represents a prototype parameter that must be a array.
	Array ParamType = "array"
)

func (ParamType) String

func (pt ParamType) String() string

type Prototype added in v0.11.0

type Prototype struct {
	APIVersion string `json:"apiVersion"`
	Kind       string `json:"kind"`

	// Unique identifier of the mixin library. The most reliable way to make a
	// name unique is to embed a domain you own into the name, as is commonly done
	// in the Java community.
	Name     string        `json:"name"`
	Params   ParamSchemas  `json:"params"`
	Template SnippetSchema `json:"template"`
	Version  string        `json:"-"` // Version of container package. Not serialized.
}

Prototype is the JSON-serializable representation of a prototype specification.

func JsonnetParse added in v0.11.0

func JsonnetParse(src string) (*Prototype, error)

JsonnetParse parses a source Jsonnet document into a Prototype.

func Unmarshal

func Unmarshal(bytes []byte) (*Prototype, error)

Unmarshal takes the bytes of a JSON-encoded prototype specification, and de-serializes them to a `SpecificationSchema`.

func (*Prototype) OptionalParams added in v0.11.0

func (s *Prototype) OptionalParams() ParamSchemas

OptionalParams retrieves all parameters that can optionally be provided to a prototype.

func (*Prototype) RequiredParams added in v0.11.0

func (s *Prototype) RequiredParams() ParamSchemas

RequiredParams retrieves all parameters that are required by a prototype.

type Prototypes added in v0.11.0

type Prototypes []*Prototype

Prototypes is a slice of pointer to `SpecificationSchema`.

func (Prototypes) SortByVersion added in v0.12.0

func (p Prototypes) SortByVersion()

SortByVersion sorts a prototype list by package version.

type SearchOptions

type SearchOptions int

SearchOptions represents the type of prototype search to execute on an `Index`.

const (
	// Prefix represents a search over prototype name prefixes.
	Prefix SearchOptions = iota

	// Suffix represents a search over prototype name suffixes.
	Suffix

	// Substring represents a search over substrings of prototype names.
	Substring
)

type SnippetSchema

type SnippetSchema struct {
	Prefix string `json:"prefix"`

	// Description describes what the prototype does.
	Description string `json:"description"`

	// ShortDescription briefly describes what the prototype does.
	ShortDescription string `json:"shortDescription"`

	// Various body types of the prototype. Follows the TextMate snippets syntax,
	// with several features disallowed. At least one of these is required to be
	// filled out.
	JSONBody    []string `json:"jsonBody"`
	YAMLBody    []string `json:"yamlBody"`
	JsonnetBody []string `json:"jsonnetBody"`
}

SnippetSchema is the JSON-serializable representation of the TextMate snippet specification, as implemented by the Language Server Protocol.

func (*SnippetSchema) AvailableTemplates

func (schema *SnippetSchema) AvailableTemplates() (ts []TemplateType)

AvailableTemplates returns the list of available `TemplateType`s this prototype implements.

func (*SnippetSchema) Body

func (schema *SnippetSchema) Body(t TemplateType) (template []string, err error)

Body attempts to retrieve the template body associated with some type `t`.

type TemplateType

type TemplateType string

TemplateType represents the possible type of a prototype.

const (
	// YAML represents a prototype written in YAML.
	YAML TemplateType = "yaml"

	// JSON represents a prototype written in JSON.
	JSON TemplateType = "json"

	// Jsonnet represents a prototype written in Jsonnet.
	Jsonnet TemplateType = "jsonnet"
)

func ParseTemplateType

func ParseTemplateType(t string) (TemplateType, error)

ParseTemplateType attempts to parse a string as a `TemplateType`.

type ValuesFile added in v0.12.0

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

ValuesFile represents a prototype values file.

func NewValuesFile added in v0.12.0

func NewValuesFile(src string) *ValuesFile

NewValuesFile creates an instance of ValuesFile.

func ReadValues added in v0.12.0

func ReadValues(r io.Reader) (*ValuesFile, error)

ReadValues reads a values file from a reader.

func (*ValuesFile) Get added in v0.12.0

func (vf *ValuesFile) Get(k string) (string, error)

Get gets a value from the values file by key.

func (*ValuesFile) Keys added in v0.12.0

func (vf *ValuesFile) Keys() ([]string, error)

Keys returns the keys in the values file.

Directories

Path Synopsis
Package snippet provides primitives for parsing and evaluating TextMate snippets.
Package snippet provides primitives for parsing and evaluating TextMate snippets.

Jump to

Keyboard shortcuts

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