Documentation ¶
Index ¶
- func DeriveFile(filename string, w io.Writer, sink Sink) error
- func DeriveStream(r io.Reader, w io.Writer, filename string, sink Sink) error
- func EditStream(r io.Reader, w io.Writer, filename string, filter Filter) error
- func GetAttributeValueAsString(attr *hclwrite.Attribute, withComments bool) (string, error)
- func ReadFile(filename string, w io.Writer, filter Filter) error
- func UpdateFile(filename string, filter Filter) error
- func VerticalFormat(tokens hclwrite.Tokens) hclwrite.Tokens
- type AttributeAppendFilter
- type AttributeGetSink
- type AttributeRemoveFilter
- type AttributeSetFilter
- type BlockAppendFilter
- type BlockGetFilter
- type BlockListSink
- type BlockRemoveFilter
- type BlockRenameFilter
- type BodyGetFilter
- type Client
- type DefaultFormatter
- type DeriveOperator
- type EditOperator
- type Filter
- func NewAttributeAppendFilter(address string, value string, newline bool) Filter
- func NewAttributeRemoveFilter(address string) Filter
- func NewAttributeSetFilter(address string, value string) Filter
- func NewBlockAppendFilter(parent string, child string, newline bool) Filter
- func NewBlockGetFilter(address string) Filter
- func NewBlockRemoveFilter(address string) Filter
- func NewBlockRenameFilter(from string, to string) Filter
- func NewBodyGetFilter(address string) Filter
- func NewFormatterFilter() Filter
- func NewMultiFilter(filters []Filter) Filter
- type Formatter
- type FormatterFilter
- type MultiFilter
- type Operator
- type Option
- type ParserSource
- type Sink
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveFile ¶ added in v0.2.0
DeriveFile is a helper method which builds an DeriveOperator from a given sink and applies it to a single file. The outputs are written to stream.
func DeriveStream ¶ added in v0.2.0
DeriveStream is a helper method which builds a DeriveOperator from a given sink and applies it to stream. Note that a filename is used only for an error message.
func EditStream ¶ added in v0.2.0
EditStream is a helper method which builds an EditorOperator from a given filter and applies it to stream. Note that a filename is used only for an error message.
func GetAttributeValueAsString ¶ added in v0.2.4
GetAttributeValueAsString returns a value of Attribute as string. There is no way to get value as string directly, so we parses tokens of Attribute and build string representation.
func ReadFile ¶ added in v0.2.0
ReadFile is a helper method which builds an EditorOperator from a given filter and applies it to a single file. The outputs are written to stream.
func UpdateFile ¶ added in v0.2.0
UpdateFile is a helper method which builds an EditorOperator from a given filter and applies it to a single file. The outputs are written to the input file in-place.
Types ¶
type AttributeAppendFilter ¶ added in v0.2.0
type AttributeAppendFilter struct {
// contains filtered or unexported fields
}
AttributeAppendFilter is a filter implementation for appending attribute.
func (*AttributeAppendFilter) Filter ¶ added in v0.2.0
Filter reads HCL and appends a new attribute to a given address. If a matched block not found, nothing happens. If the given attribute already exists, it returns an error. If a newline flag is true, it also appends a newline before the new attribute.
type AttributeGetSink ¶ added in v0.2.0
type AttributeGetSink struct {
// contains filtered or unexported fields
}
AttributeGetSink is a sink implementation for getting a value of attribute.
type AttributeRemoveFilter ¶ added in v0.2.0
type AttributeRemoveFilter struct {
// contains filtered or unexported fields
}
AttributeRemoveFilter is a filter implementation for removing attribute.
type AttributeSetFilter ¶ added in v0.2.0
type AttributeSetFilter struct {
// contains filtered or unexported fields
}
AttributeSetFilter is a filter implementation for setting attribute.
type BlockAppendFilter ¶ added in v0.2.0
type BlockAppendFilter struct {
// contains filtered or unexported fields
}
BlockAppendFilter is a filter implementation for appending block.
type BlockGetFilter ¶ added in v0.2.0
type BlockGetFilter struct {
// contains filtered or unexported fields
}
BlockGetFilter is a filter implementation for getting block.
type BlockListSink ¶ added in v0.2.0
type BlockListSink struct{}
BlockListSink is a sink implementation for getting a list of block addresses.
type BlockRemoveFilter ¶ added in v0.2.0
type BlockRemoveFilter struct {
// contains filtered or unexported fields
}
BlockRemoveFilter is a filter implementation for removing block.
type BlockRenameFilter ¶ added in v0.2.0
type BlockRenameFilter struct {
// contains filtered or unexported fields
}
BlockRenameFilter is a filter implementation for renaming block.
func (*BlockRenameFilter) Filter ¶ added in v0.2.0
Filter reads HCL and renames matched blocks at a given address. The blocks which do not match the from address are output as is. Rename means setting the block type and labels corresponding to the new address. changing the block type does not make sense on an application context, but filters can chain to others and the later filter may edit its attributes. So we allow this filter to any block type and labels.
type BodyGetFilter ¶ added in v0.2.0
type BodyGetFilter struct {
// contains filtered or unexported fields
}
BodyGetFilter is a filter implementation for getting body of first matched block.
type Client ¶ added in v0.2.0
type Client interface { // Edit reads a HCL file and appies a given filter. // If filename is `-`, reads the input from stdin. // If update is true, the outputs is written to the input file, else to stdout. Edit(filename string, update bool, filter Filter) error // Derive reads a HCL file and appies a given sink. // If filename is `-`, reads the input from stdin. // The outputs is always written to stdout. Derive(filename string, sink Sink) error }
Client is an interface for the entrypoint of editor package
type DefaultFormatter ¶ added in v0.2.0
type DefaultFormatter struct { }
DefaultFormatter is a default Formatter implementation for formatting HCL.
type DeriveOperator ¶ added in v0.2.0
type DeriveOperator struct {
// contains filtered or unexported fields
}
DeriveOperator is an implementation of Operator for deriving any bytes from HCL.
func (*DeriveOperator) Apply ¶ added in v0.2.0
func (o *DeriveOperator) Apply(input []byte, filename string) ([]byte, error)
Apply reads an input bytes, applies a given sink for deriving, and writes output. The input contains arbitrary bytes in HCL, and the output contains arbitrary bytes in non-HCL. Note that a filename is used only for an error message.
type EditOperator ¶ added in v0.2.0
type EditOperator struct {
// contains filtered or unexported fields
}
EditOperator is an implementation of Operator for editing HCL.
func (*EditOperator) Apply ¶ added in v0.2.0
func (o *EditOperator) Apply(input []byte, filename string) ([]byte, error)
Apply reads input bytes, applies some filters and formatter, and writes output. The input and output contain arbitrary bytes in HCL. Note that a filename is used only for an error message.
type Filter ¶
type Filter interface { // Filter reads HCL and writes HCL Filter(*hclwrite.File) (*hclwrite.File, error) }
Filter is an interface which reads HCL and writes HCL
func NewAttributeAppendFilter ¶ added in v0.2.0
NewAttributeAppendFilter creates a new instance of AttributeAppendFilter.
func NewAttributeRemoveFilter ¶ added in v0.2.0
NewAttributeRemoveFilter creates a new instance of AttributeRemoveFilter.
func NewAttributeSetFilter ¶ added in v0.2.0
NewAttributeSetFilter creates a new instance of AttributeSetFilter.
func NewBlockAppendFilter ¶ added in v0.2.0
NewBlockAppendFilter creates a new instance of BlockAppendFilter.
func NewBlockGetFilter ¶ added in v0.2.0
NewBlockGetFilter creates a new instance of BlockGetFilter.
func NewBlockRemoveFilter ¶ added in v0.2.0
NewBlockRemoveFilter creates a new instance of BlockRemoveFilter.
func NewBlockRenameFilter ¶ added in v0.2.0
NewBlockRenameFilter creates a new instance of BlockRenameFilter.
func NewBodyGetFilter ¶ added in v0.2.0
NewBodyGetFilter creates a new instance of BodyGetFilter.
func NewFormatterFilter ¶ added in v0.2.0
func NewFormatterFilter() Filter
NewFormatterFilter creates a new instance of FormatterFilter.
func NewMultiFilter ¶ added in v0.2.0
NewMultiFilter creates a new instance of MultiFilter.
type Formatter ¶ added in v0.2.0
type Formatter interface { // Format reads HCL, formats tokens and writes bytes. Format(*hclwrite.File) ([]byte, error) }
Formatter is an interface which reads HCL, formats tokens and writes bytes. Formatter has a signature similar to Sink, but they have different features, so we distinguish them with types.
func NewDefaultFormatter ¶ added in v0.2.0
func NewDefaultFormatter() Formatter
NewDefaultFormatter creates a new instance of DefaultFormatter.
type FormatterFilter ¶ added in v0.2.0
type FormatterFilter struct { }
FormatterFilter is a Filter implementation which applies the default formatter as a Filter.
type MultiFilter ¶ added in v0.2.0
type MultiFilter struct {
// contains filtered or unexported fields
}
MultiFilter is a Filter implementation which applies multiple filters in sequence.
type Operator ¶ added in v0.2.0
type Operator interface { // Apply reads input bytes, apply some operations, and writes outputs. // The input and output contain arbitrary bytes (maybe HCL or not). // Note that a filename is used only for an error message. Apply(input []byte, filename string) ([]byte, error) }
Operator is an interface which abstracts stream operations. The hcledit provides not only operations for editing HCL, but also for deriving such as listing. They need similar but different implementations.
func NewDeriveOperator ¶ added in v0.2.0
NewDeriveOperator creates a new instance of operator for deriving any bytes from HCL.
func NewEditOperator ¶ added in v0.2.0
NewEditOperator creates a new instance of operator for editing HCL. If you want to apply multiple filters, use the MultiFilter to compose them.
type Option ¶ added in v0.2.0
type Option struct { // InStream is the stdin stream. InStream io.Reader // OutStream is the stdout stream. OutStream io.Writer // ErrStream is the stderr stream. ErrStream io.Writer }
Option is a set of options for Client.
type ParserSource ¶ added in v0.2.0
type ParserSource struct { }
ParserSource is a Source implementation for parsing HCL.
type Sink ¶
Sink is an interface which reads HCL and writes bytes.
func NewAttributeGetSink ¶ added in v0.2.0
NewAttributeGetSink creates a new instance of AttributeGetSink.
func NewBlockListSink ¶ added in v0.2.0
func NewBlockListSink() Sink
NewBlockListSink creates a new instance of BlockListSink.
type Source ¶
type Source interface { // Source parses HCL and returns *hclwrite.File // filename is a metadata of input stream and used only for an error message. Source(src []byte, filename string) (*hclwrite.File, error) }
Source is an interface which reads string and writes HCL
func NewParserSource ¶ added in v0.2.0
func NewParserSource() Source
NewParserSource creates a new instance of ParserSource.
Source Files ¶
- address.go
- client.go
- filter_attribute_append.go
- filter_attribute_remove.go
- filter_attribute_set.go
- filter_block_append.go
- filter_block_get.go
- filter_block_remove.go
- filter_block_rename.go
- filter_body_get.go
- filter_formatter.go
- filter_multi.go
- filter_vertical_formatter.go
- formatter_default.go
- operator.go
- operator_derive.go
- operator_edit.go
- sink_attribute_get.go
- sink_block_list.go
- source_parser.go
- test_helper.go