Documentation ¶
Index ¶
- Constants
- Variables
- func BuildCumulocityQuery(cmd *cobra.Command, fixedParts []string, orderBy string) func([]byte) []byte
- func ExactArgsOrExample(n int) cobra.PositionalArgs
- func FilterJsonLines(line []byte) bool
- func GetCollectionPropertyFromAnnotation(cmd *cobra.Command) (value string)
- func GetDeprecationNoticeFromAnnotation(cmd *cobra.Command) (value string)
- func GetDuration(v string, inferUnit bool, unit time.Duration) (time.Duration, error)
- func GetDurationFlag(cmd *cobra.Command, name string, inferUnit bool, unit time.Duration) (time.Duration, error)
- func GetFlagStringValues(cmd *cobra.Command, name string) ([]string, error)
- func GetIDArray(values []string) (ids []string)
- func GetIDs(cmd *cobra.Command, args []string) (ids []string)
- func GetStringFromAnnotation(cmd *cobra.Command, path string) (value string)
- func HasValueFromPipeline(cmd *cobra.Command, name string) bool
- func NewFlagFileContents(cmd *cobra.Command, name string) (iterator.Iterator, error)
- func NewFlagWithPipeIterator(cmd *cobra.Command, pipeOpt *PipelineOptions, supportsPipeline bool) (iterator.Iterator, error)
- func UnpackGetterOptions(defaultFormat string, options ...string) (src string, dst string, formatter string)
- func ValidateID(v []byte) (err error)
- func WithBody(cmd *cobra.Command, body *mapbuilder.MapBuilder, ...) (err error)
- func WithC8YQueryOptions(cmd *cobra.Command, inputIterators *RequestInputIterators, opts ...GetOption) ([]string, error)
- func WithFormDataOptions(cmd *cobra.Command, form map[string]io.Reader, ...) (err error)
- func WithHeaders(cmd *cobra.Command, header http.Header, inputIterators *RequestInputIterators, ...) (err error)
- func WithOptions(cmd *cobra.Command, opts ...Option) *cobra.Command
- func WithPathParameters(cmd *cobra.Command, path *StringTemplate, ...) (err error)
- func WithQueryParameters(cmd *cobra.Command, query *QueryTemplate, ...) (err error)
- func WithRequestOptions(cmd *cobra.Command, args []string, req *c8y.RequestOptions, ...) (err error)
- type Action
- type DefaultTemplateString
- type DurationGenerator
- type FilePath
- type GetOption
- func WithBoolValue(opts ...string) GetOption
- func WithCertificateFile(opts ...string) GetOption
- func WithCumulocityQuery(queryOptions []GetOption, opts ...string) GetOption
- func WithCurrentPage() GetOption
- func WithCustomStringSlice(valuesFunc func() ([]string, error), opts ...string) GetOption
- func WithCustomStringValue(transform func([]byte) []byte, targetFunc func() string, opts ...string) GetOption
- func WithDataFlagValue() GetOption
- func WithDataValue(opts ...string) GetOption
- func WithDataValueAdvanced(stripCumulocityKeys bool, raw bool, opts ...string) GetOption
- func WithDefaultBoolValue(opts ...string) GetOption
- func WithDefaultTemplateString(value string) GetOption
- func WithEncodedRelativeTimestamp(opts ...string) GetOption
- func WithFileBaseName(opts ...string) GetOption
- func WithFileMIMEType(name string, opts ...string) GetOption
- func WithFilePath(opts ...string) GetOption
- func WithFileReader(opts ...string) GetOption
- func WithFloatValue(opts ...string) GetOption
- func WithFormDataFile(srcFile string, srcData string) []GetOption
- func WithFormDataFileAndInfo(srcFile string, srcData string) []GetOption
- func WithFormDataFileAndInfoWithTemplateSupport(templateResolver Resolver, srcFile string, srcData string) []GetOption
- func WithIntValue(opts ...string) GetOption
- func WithInventoryChildType(opts ...string) GetOption
- func WithOptionalFragment(opts ...string) GetOption
- func WithOverrideValue(opts ...string) GetOption
- func WithPageSize() GetOption
- func WithPipelineIterator(opts *PipelineOptions) GetOption
- func WithProcessingModeValue() GetOption
- func WithRelativeDate(encode bool, opts ...string) GetOption
- func WithRelativeTimestamp(opts ...string) GetOption
- func WithRequiredProperties(values ...string) GetOption
- func WithRequiredTemplateString(value string) GetOption
- func WithStaticStringValue(opts ...string) GetOption
- func WithStringDefaultValue(defaultValue string, opts ...string) GetOption
- func WithStringFormValue(opts ...string) GetOption
- func WithStringSliceCSV(opts ...string) GetOption
- func WithStringSliceValues(opts ...string) GetOption
- func WithStringValue(opts ...string) GetOption
- func WithTemplateOptions(templateName string, variablesName string, pathResolver Resolver) []GetOption
- func WithTemplateString(value string, applyLast bool) GetOption
- func WithTemplateValue(src string, pathResolver Resolver) GetOption
- func WithTemplateVariablesValue(src ...string) GetOption
- func WithTotalElements() GetOption
- func WithTotalPages() GetOption
- func WithVersion(fallbackSrc string, opts ...string) GetOption
- type Option
- func WithBatchOptions(acceptInputFile bool) Option
- func WithCollectionProperty(property string) Option
- func WithCommonCumulocityQueryOptions() Option
- func WithData() Option
- func WithDeprecationNotice(message string) Option
- func WithExtendedPipelineSupport(name string, property string, required bool, aliases ...string) Option
- func WithPipelineAliases(property string, aliases ...string) Option
- func WithPipelineSupport(name string) Option
- func WithProcessingMode() Option
- func WithRuntimePipelineProperty() Option
- func WithTemplateNoCompletion() Option
- type ParameterError
- type PipelineOptions
- type QueryTemplate
- func (b *QueryTemplate) Execute(ignoreIterators bool) (query url.Values, err error)
- func (b *QueryTemplate) GetNext() ([]byte, interface{}, error)
- func (b *QueryTemplate) GetQueryUnescape(ignoreIterators bool) (string, error)
- func (b *QueryTemplate) HasVariable(name string) bool
- func (b *QueryTemplate) IsBound() bool
- func (b *QueryTemplate) SetVariable(name string, value interface{})
- type RawString
- type RequestBuilder
- type RequestInputIterators
- type RequiredKeys
- type RequiredTemplateString
- type Resolver
- type StringTemplate
- func (b *StringTemplate) CheckRequired() error
- func (b *StringTemplate) Execute(ignoreIterators bool, template ...string) (output string, input interface{}, err error)
- func (b *StringTemplate) GetNext() ([]byte, interface{}, error)
- func (b *StringTemplate) GetTemplate() string
- func (b *StringTemplate) IsBound() bool
- func (b *StringTemplate) SetAllowEmptyValues(value bool)
- func (b *StringTemplate) SetTemplate(template string)
- func (b *StringTemplate) SetVariable(name string, value interface{})
- type Template
- type TemplateVariables
Constants ¶
const ( FlagDataName = "data" FlagDataTemplateName = "template" FlagDataTemplateVariablesName = "templateVars" FlagProcessingModeName = "processingMode" FlagWithTotalPages = "withTotalPages" FlagWithTotalElements = "withTotalElements" FlagPageSize = "pageSize" FlagCurrentPage = "currentPage" FlagNullInput = "nullInput" FlagAllowEmptyPipe = "allowEmptyPipe" FlagReadFromPipeText = "-" FlagReadFromPipeJSON = "-." )
const ( AnnotationValuePipelineAlias = "pipelineAliases" AnnotationValueFromPipeline = "valueFromPipeline" AnnotationValueFromPipelineData = "valueFromPipeline.data" AnnotationValueCollectionProperty = "collectionProperty" AnnotationValueDeprecated = "deprecatedNotice" )
Variables ¶
var ErrFlagDoesNotExist = errors.New("Flag does not exist")
var ErrFlagError = errors.New("failed to parse arguments")
var ErrInvalidDuration = errors.New("invalid duration")
ErrInvalidDuration invalid duration
var ErrInvalidIDFormat = errors.New("invalid id format")
ErrInvalidIDFormat invalid ID foratm
var ErrInvalidJSON = errors.New("invalid json")
var ErrParameterMissing error = errors.New("missing required parameter")
var ErrReadFile = errors.New("failed to read file")
var ErrUnsupportedType = errors.New("unsupported type")
Functions ¶
func BuildCumulocityQuery ¶
func ExactArgsOrExample ¶
func ExactArgsOrExample(n int) cobra.PositionalArgs
ExactArgsOrExample returns an error if there are not exactly n args or --exapmles is not used
func FilterJsonLines ¶
func GetCollectionPropertyFromAnnotation ¶
GetCollectionPropertyFromAnnotation returns the collection property path used to return a subset of the json response by default
func GetDeprecationNoticeFromAnnotation ¶ added in v2.15.0
GetDeprecationNoticeFromAnnotation returns the deprecated notice if present
func GetDuration ¶
GetDuration get duration with an option of assuming the string is referring to seconds
func GetDurationFlag ¶
func GetFlagStringValues ¶
GetFlagStringValues get string slice from either a string slice or string flag
func GetIDArray ¶
func GetIDs ¶
GetIDs returns a list of IDs --id 1234,1234 (comma seperated list (without spaces!)) --id "22437097744 1235" [22437097744, 1235] --id 22437097744 1235,1234 (requires positional arguments as well) --id 22437097744 1235,1234 asdfasdf asdfasdf will be ignored as it does not match the pattern
func GetStringFromAnnotation ¶
GetStringFromAnnotation returns a string value stored in the annotations
func HasValueFromPipeline ¶
HasValueFromPipeline checks if the given flag name supported values from pipeline It checks the command for a special annotation
func NewFlagFileContents ¶
NewFlagFileContents returns iterator which will interate over the lines in a file
func NewFlagWithPipeIterator ¶
func NewFlagWithPipeIterator(cmd *cobra.Command, pipeOpt *PipelineOptions, supportsPipeline bool) (iterator.Iterator, error)
NewFlagWithPipeIterator creates an iterator from a command argument or from the pipeline It will automatically try to get the value from a String or a StringSlice flag
func UnpackGetterOptions ¶
func ValidateID ¶
ValidateID returns an error if the input value does not match an id
func WithBody ¶
func WithBody(cmd *cobra.Command, body *mapbuilder.MapBuilder, inputIterators *RequestInputIterators, opts ...GetOption) (err error)
WithBody returns a body from given command line arguments
func WithC8YQueryOptions ¶
func WithC8YQueryOptions(cmd *cobra.Command, inputIterators *RequestInputIterators, opts ...GetOption) ([]string, error)
WithC8YQueryOptions applies given options to a URL Query parameters
func WithFormDataOptions ¶
func WithFormDataOptions(cmd *cobra.Command, form map[string]io.Reader, inputIterators *RequestInputIterators, opts ...GetOption) (err error)
WithFormDataOptions returns a body from given command line arguments
func WithHeaders ¶
func WithHeaders(cmd *cobra.Command, header http.Header, inputIterators *RequestInputIterators, opts ...GetOption) (err error)
WithHeaders sets header values from command line arguments
func WithOptions ¶
WithOptions applies given options to the command
func WithPathParameters ¶
func WithPathParameters(cmd *cobra.Command, path *StringTemplate, inputIterators *RequestInputIterators, opts ...GetOption) (err error)
WithPathParameters returns a path parameter values given from command line arguments
func WithQueryParameters ¶
func WithQueryParameters(cmd *cobra.Command, query *QueryTemplate, inputIterators *RequestInputIterators, opts ...GetOption) (err error)
WithQueryParameters returns a query parameter values given from command line arguments
func WithRequestOptions ¶
func WithRequestOptions(cmd *cobra.Command, args []string, req *c8y.RequestOptions, builderOpts *RequestBuilder) (err error)
Types ¶
type DefaultTemplateString ¶
type DefaultTemplateString string
type DurationGenerator ¶
func GetDurationGenerator ¶
func GetDurationGenerator(cmd *cobra.Command, minFlag, maxFlag string, inferUnit bool, unit time.Duration) (DurationGenerator, error)
GetDurationGenerator returns a random duration generator func. The generator will return a random duration between the given min or max
type GetOption ¶
type GetOption func(cmd *cobra.Command, inputIterators *RequestInputIterators) (name string, value interface{}, err error)
GetOption gets the value from a flag and returns the value which can be set accordingly
func WithBoolValue ¶
WithBoolValue adds a boolean value from cli arguments to a query parameter
func WithCertificateFile ¶ added in v2.13.0
WithCertificateFile adds a PEM certificate file contents
func WithCumulocityQuery ¶ added in v2.15.0
WithCumulocityQuery build a Cumulocity Query Expression
func WithCurrentPage ¶
func WithCurrentPage() GetOption
func WithCustomStringSlice ¶
WithCustomStringSlice adds string map values from cli arguments
func WithCustomStringValue ¶
func WithCustomStringValue(transform func([]byte) []byte, targetFunc func() string, opts ...string) GetOption
WithCustomStringValue add a custom string value with a custom tranform function
func WithDataFlagValue ¶
func WithDataFlagValue() GetOption
func WithDataValue ¶
func WithDataValueAdvanced ¶
WithDataValueAdvanced adds json or shorthand json parsing with additional option to strip the Cumulocity properties from the input
func WithDefaultBoolValue ¶
WithDefaultBoolValue sets a boolean value regardless if the value has been provided by the flag or not
func WithEncodedRelativeTimestamp ¶
WithEncodedRelativeTimestamp adds a encoded timestamp (string) value from cli arguments
func WithFileBaseName ¶
WithFileBaseName adds the filename basename from cli arguments
func WithFileMIMEType ¶
WithFileMIMEType adds the file MIME type from cli arguments
func WithFilePath ¶
WithFilePath adds a file path from cli arguments
func WithFileReader ¶
WithFileReader adds file (as reader) from cli arguments
func WithFloatValue ¶
WithFloatValue adds a float (float32) value from cli arguments
func WithFormDataFile ¶
WithFormDataFile adds form data from cli arguments
func WithFormDataFileAndInfo ¶
WithFormDataFileAndInfo adds form data from cli arguments
func WithFormDataFileAndInfoWithTemplateSupport ¶ added in v2.14.0
func WithIntValue ¶
WithIntValue adds a integer (int) value from cli arguments
func WithInventoryChildType ¶ added in v2.15.0
func WithOptionalFragment ¶
WithOptionalFragment adds fragment if the boolean value is true a boolean value from cli arguments to a query parameter
func WithOverrideValue ¶
WithOverrideValue adds an options to override a value via cli arguments. Pipeline input is ignored if this value is present However if the argument refers to an existing file then the value will be ignored!
func WithPageSize ¶
func WithPageSize() GetOption
func WithPipelineIterator ¶
func WithPipelineIterator(opts *PipelineOptions) GetOption
WithPipelineIterator adds pipeline support from cli arguments
func WithProcessingModeValue ¶
func WithProcessingModeValue() GetOption
WithProcessingModeValue adds the processing module value from cli arguments
func WithRelativeDate ¶
WithRelativeDate adds a date (only, no time) (string) value from cli arguments
func WithRelativeTimestamp ¶
WithRelativeTimestamp adds a timestamp (string) value from cli arguments
func WithRequiredProperties ¶
func WithStaticStringValue ¶
WithStaticStringValue add a fixed string value
func WithStringDefaultValue ¶
WithStringDefaultValue adds a string value from cli arguments
func WithStringFormValue ¶ added in v2.14.0
WithStringFormValue adds string (as reader) from cli arguments
func WithStringSliceCSV ¶
WithStringSliceCSV adds a string slice as comma separated variables from cli arguments
func WithStringSliceValues ¶
WithStringSliceValues adds a string slice from cli arguments
func WithStringValue ¶
WithStringValue adds a string value from cli arguments
func WithTemplateOptions ¶
func WithTemplateString ¶
func WithTemplateValue ¶
func WithTotalElements ¶ added in v2.16.0
func WithTotalElements() GetOption
func WithTotalPages ¶
func WithTotalPages() GetOption
func WithVersion ¶
type Option ¶
Option adds flags to a given command
func WithBatchOptions ¶
WithBatchOptions adds support for batch options
func WithCollectionProperty ¶
WithCollectionProperty adds the default property to be plucked from the raw json response so that the important information is returned by default
func WithCommonCumulocityQueryOptions ¶
func WithCommonCumulocityQueryOptions() Option
WithCommonCumulocityQueryOptions adds support for common query parameter options like query, orderBy etc.
func WithDeprecationNotice ¶ added in v2.15.0
WithDeprecationNotice marks a commands as being deprecated
func WithPipelineAliases ¶ added in v2.17.0
WithPipelineAliases adds a list of aliases for a flag if it is selected to be sourced from the pipeline
func WithPipelineSupport ¶
WithPipelineSupport adds support for pipeline to a argument
func WithProcessingMode ¶
func WithProcessingMode() Option
WithProcessingMode adds support for processing mode
func WithRuntimePipelineProperty ¶ added in v2.17.0
func WithRuntimePipelineProperty() Option
func WithTemplateNoCompletion ¶ added in v2.18.0
func WithTemplateNoCompletion() Option
WithTemplateNoCompletion adds support for templates
type ParameterError ¶
func (*ParameterError) Error ¶
func (e *ParameterError) Error() string
type PipelineOptions ¶
type PipelineOptions struct { Name string `json:"name"` Required bool `json:"required"` EmptyPipe bool `json:"allowEmptyPipe"` Disabled bool `json:"disabled"` Property string `json:"property"` Aliases []string `json:"aliases"` IsID bool `json:"isID"` Validator iterator.Validator `json:"-"` Formatter func([]byte) []byte `json:"-"` Format string `json:"-"` InputFilter func([]byte) bool `json:"-"` PostActions []Action `json:"-"` }
func GetPipeOptionsFromAnnotation ¶
func GetPipeOptionsFromAnnotation(cmd *cobra.Command) (options *PipelineOptions, err error)
GetPipeOptionsFromAnnotation returns the pipeline options stored in the annotations
type QueryTemplate ¶
type QueryTemplate struct {
// contains filtered or unexported fields
}
QueryTemplate is an iterator that can be used to construct HTTP request queries
func NewQueryTemplate ¶
func NewQueryTemplate() *QueryTemplate
NewQueryTemplate returns a new query iterator template
func (*QueryTemplate) Execute ¶
func (b *QueryTemplate) Execute(ignoreIterators bool) (query url.Values, err error)
Execute evalulates the variables and returns a query parameters which can be used for rest requests
func (*QueryTemplate) GetNext ¶
func (b *QueryTemplate) GetNext() ([]byte, interface{}, error)
GetNext returns the next template path
func (*QueryTemplate) GetQueryUnescape ¶
func (b *QueryTemplate) GetQueryUnescape(ignoreIterators bool) (string, error)
GetQueryUnescape returns the unescaped query. User can choose whether iterators are evalulated or not
func (*QueryTemplate) HasVariable ¶
func (b *QueryTemplate) HasVariable(name string) bool
HasVariable returns true if the variable has already been defined
func (*QueryTemplate) IsBound ¶
func (b *QueryTemplate) IsBound() bool
IsBound return true if the iterator is bound
func (*QueryTemplate) SetVariable ¶
func (b *QueryTemplate) SetVariable(name string, value interface{})
SetVariable sets a give path variable which will be evalulated when fetching the next value
type RequestBuilder ¶
type RequestInputIterators ¶
type RequestInputIterators struct { Total int Path *StringTemplate Body *mapbuilder.MapBuilder Query *QueryTemplate PipeOptions *PipelineOptions }
RequestInputIterators contains all request input iterators
type RequiredKeys ¶
type RequiredKeys []string
type RequiredTemplateString ¶
type RequiredTemplateString string
type StringTemplate ¶
type StringTemplate struct {
// contains filtered or unexported fields
}
StringTemplate is a template which can input parameters which will be ev
func NewStringTemplate ¶
func NewStringTemplate(template string) *StringTemplate
NewStringTemplate returns a new string template
func (*StringTemplate) CheckRequired ¶
func (b *StringTemplate) CheckRequired() error
CheckRequired check if all required variables are provided
func (*StringTemplate) Execute ¶
func (b *StringTemplate) Execute(ignoreIterators bool, template ...string) (output string, input interface{}, err error)
Execute replaces all of the path parameters in a given URI with the provided values Example:
"alarm/alarms/{id}" => "alarm/alarms/1234" if given a parameter map of {"id": "1234"}
func (*StringTemplate) GetNext ¶
func (b *StringTemplate) GetNext() ([]byte, interface{}, error)
GetNext returns the next template path
func (*StringTemplate) GetTemplate ¶
func (b *StringTemplate) GetTemplate() string
GetTemplate return the string template
func (*StringTemplate) IsBound ¶
func (b *StringTemplate) IsBound() bool
IsBound return true if the iterator is bound
func (*StringTemplate) SetAllowEmptyValues ¶
func (b *StringTemplate) SetAllowEmptyValues(value bool)
func (*StringTemplate) SetTemplate ¶
func (b *StringTemplate) SetTemplate(template string)
SetTemplate updates the string template
func (*StringTemplate) SetVariable ¶
func (b *StringTemplate) SetVariable(name string, value interface{})
SetVariable sets a give path variable which will be evalulated when fetching the next value
type TemplateVariables ¶
type TemplateVariables map[string]interface{}