proptools

package
v0.0.0-...-9c402f9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendMatchingProperties

func AppendMatchingProperties(dst []interface{}, src interface{},
	filter ExtendPropertyFilterFunc) error

AppendMatchingProperties appends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.

The filter function can prevent individual properties from being appended by returning false, or abort AppendProperties with an error by returning an error. Passing nil for filter will append all properties.

An error returned by AppendMatchingProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The append operation is defined as appending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending the zero value of a property will always be a no-op.

func AppendProperties

func AppendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error

AppendProperties appends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.

The filter function can prevent individual properties from being appended by returning false, or abort AppendProperties with an error by returning an error. Passing nil for filter will append all properties.

An error returned by AppendProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The append operation is defined as appending strings and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending the zero value of a property will always be a no-op.

func Bool

func Bool(b *bool) bool

Bool takes a pointer to a bool and returns true iff the pointer is non-nil and points to a true value.

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a new bool containing the given value.

func CloneEmptyProperties

func CloneEmptyProperties(structValue reflect.Value) reflect.Value

func CloneProperties

func CloneProperties(structValue reflect.Value) reflect.Value

func CopyProperties

func CopyProperties(dstValue, srcValue reflect.Value)

func ExtendMatchingProperties

func ExtendMatchingProperties(dst []interface{}, src interface{},
	filter ExtendPropertyFilterFunc, order ExtendPropertyOrderFunc) error

ExtendMatchingProperties appends or prepends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.

The filter function can prevent individual properties from being appended or prepended by returning false, or abort ExtendMatchingProperties with an error by returning an error. Passing nil for filter will append or prepend all properties.

The order function is called on each non-filtered property to determine if it should be appended or prepended.

An error returned by ExtendMatchingProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The append operation is defined as appending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending or prepending the zero value of a property will always be a no-op.

func ExtendProperties

func ExtendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc,
	order ExtendPropertyOrderFunc) error

ExtendProperties appends or prepends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.

The filter function can prevent individual properties from being appended or prepended by returning false, or abort ExtendProperties with an error by returning an error. Passing nil for filter will append or prepend all properties.

The order function is called on each non-filtered property to determine if it should be appended or prepended.

An error returned by ExtendProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The append operation is defined as appending strings and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Appending or prepending the zero value of a property will always be a no-op.

func FieldNameForProperty

func FieldNameForProperty(propertyName string) string

func HasTag

func HasTag(field reflect.StructField, name, value string) bool

func NinjaAndShellEscape

func NinjaAndShellEscape(slice []string) []string

func NinjaEscape

func NinjaEscape(slice []string) []string

NinjaEscape takes a slice of strings that may contain characters that are meaningful to ninja ($), and escapes each string so they will be passed to bash. It is not necessary on input, output, or dependency names, those are handled by ModuleContext.Build. It is generally required on strings from properties in Blueprint files that are used as Args to ModuleContext.Build. A new slice containing the escaped strings is returned.

func PrependMatchingProperties

func PrependMatchingProperties(dst []interface{}, src interface{},
	filter ExtendPropertyFilterFunc) error

PrependMatchingProperties prepends the values of properties in the property struct src to the property structs in dst. dst and src do not have to be the same type, but every property in src must be found in at least one property in dst. dst must be a slice of pointers to structs, and src must be a pointer to a struct.

The filter function can prevent individual properties from being prepended by returning false, or abort PrependProperties with an error by returning an error. Passing nil for filter will prepend all properties.

An error returned by PrependProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The prepend operation is defined as prepending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Prepending the zero value of a property will always be a no-op.

func PrependProperties

func PrependProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error

PrependProperties prepends the values of properties in the property struct src to the property struct dst. dst and src must be the same type, and both must be pointers to structs.

The filter function can prevent individual properties from being prepended by returning false, or abort PrependProperties with an error by returning an error. Passing nil for filter will prepend all properties.

An error returned by PrependProperties that applies to a specific property will be an *ExtendPropertyError, and can have the property name and error extracted from it.

The prepend operation is defined as prepending strings, and slices of strings normally, OR-ing bool values, replacing non-nil pointers to booleans or strings, and recursing into embedded structs, pointers to structs, and interfaces containing pointers to structs. Prepending the zero value of a property will always be a no-op.

func PropertyNameForField

func PropertyNameForField(fieldName string) string

func ShellEscape

func ShellEscape(slice []string) []string

ShellEscape takes a slice of strings that may contain characters that are meaningful to bash and escapes if necessary by wrapping them in single quotes, and replacing internal single quotes with '\” (one single quote to end the quoting, a shell-escaped single quote to insert a real single quote, and then a single quote to restarting quoting. A new slice containing the escaped strings is returned.

func String

func String(s *string) string

String takes a pointer to a string and returns the value of the string if the pointer is non-nil, or an empty string.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a new string containing the given value.

func TypeEqual

func TypeEqual(s1, s2 interface{}) bool

TypeEqual takes two property structs, and returns true if they are of equal type, any embedded pointers to structs or interfaces having matching nilitude, and any interface{} values in any embedded structs, pointers to structs, or interfaces are also of equal type.

func ZeroProperties

func ZeroProperties(structValue reflect.Value)

Types

type ExtendPropertyError

type ExtendPropertyError struct {
	Err      error
	Property string
}

func (*ExtendPropertyError) Error

func (e *ExtendPropertyError) Error() string

type ExtendPropertyFilterFunc

type ExtendPropertyFilterFunc func(property string,
	dstField, srcField reflect.StructField,
	dstValue, srcValue interface{}) (bool, error)

type ExtendPropertyOrderFunc

type ExtendPropertyOrderFunc func(property string,
	dstField, srcField reflect.StructField,
	dstValue, srcValue interface{}) (Order, error)

type Order

type Order int
const (
	Append Order = iota
	Prepend
)

Jump to

Keyboard shortcuts

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