Documentation ¶
Overview ¶
Package output formats and prints the response on standard output.
- Supports JSON and text output - Provides mechanism to transform output using JMESPath queries
Index ¶
Constants ¶
const FieldSeparator = "\t"
const ObjectSeparator = "\n"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultTransformer ¶
type DefaultTransformer struct { }
The DefaultTransformer simply passes through the output from the output writer. No transformation is performed.
func NewDefaultTransformer ¶ added in v1.0.56
func NewDefaultTransformer() *DefaultTransformer
func (DefaultTransformer) Execute ¶
func (t DefaultTransformer) Execute(data interface{}) (interface{}, error)
type JmesPathTransformer ¶
type JmesPathTransformer struct {
// contains filtered or unexported fields
}
The JmesPathTransformer uses the JMESPath query language to transform the executor output.
It is used when the --query parameter is provided. Example: --query "id"
{ "id": "521b4edc-ad6f-4301-909e-f96a401e1fed", }
=> "521b4edc-ad6f-4301-909e-f96a401e1fed"
See https://jmespath.org for more information.
func NewJmesPathTransformer ¶ added in v1.0.56
func NewJmesPathTransformer(query string) *JmesPathTransformer
func (JmesPathTransformer) Execute ¶
func (t JmesPathTransformer) Execute(data interface{}) (interface{}, error)
type JsonOutputWriter ¶
type JsonOutputWriter struct {
// contains filtered or unexported fields
}
The JsonOutputWriter formats the CLI output as prettified json.
It is used by default or when the --output json parameter is provided. Example:
{ "foo": "bar" }
func NewJsonOutputWriter ¶ added in v1.0.56
func NewJsonOutputWriter(output io.Writer, transformer Transformer) *JsonOutputWriter
func (JsonOutputWriter) WriteResponse ¶
func (w JsonOutputWriter) WriteResponse(response ResponseInfo) error
type MemoryOutputWriter ¶ added in v1.0.71
type MemoryOutputWriter struct {
// contains filtered or unexported fields
}
The MemoryOutputWriter keeps the response in memory so it can read multiple times.
func NewMemoryOutputWriter ¶ added in v1.0.71
func NewMemoryOutputWriter() *MemoryOutputWriter
func (MemoryOutputWriter) Response ¶ added in v1.0.71
func (w MemoryOutputWriter) Response() ResponseInfo
func (*MemoryOutputWriter) WriteResponse ¶ added in v1.0.71
func (w *MemoryOutputWriter) WriteResponse(response ResponseInfo) error
type OutputWriter ¶
type OutputWriter interface {
WriteResponse(response ResponseInfo) error
}
The OutputWriter is used to print the executor result on standard output.
type ResponseInfo ¶
type ResponseInfo struct { StatusCode int Status string Protocol string Header map[string][]string Body io.Reader }
ResponseInfo contains the information used by the output writer to print the executor result on standard output.
func NewResponseInfo ¶
type TextOutputWriter ¶
type TextOutputWriter struct {
// contains filtered or unexported fields
}
The TextOutputWriter formats the CLI output as text meaning fields are separated by tabs and multiple elements by newline.
It is used when the --output text parameter is provided. Example: foo1 bar1 foo2 bar2
func NewTextOutputWriter ¶ added in v1.0.56
func NewTextOutputWriter(output io.Writer, transformer Transformer) *TextOutputWriter
func (TextOutputWriter) WriteResponse ¶
func (w TextOutputWriter) WriteResponse(response ResponseInfo) error
type Transformer ¶
type Transformer interface {
Execute(data interface{}) (interface{}, error)
}
The Transformer interface can be implemented to provide a converter which transforms the CLI output into a different structure.