hclq

package
v0.0.0-...-e3dc4ac Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HclFromJSON

func HclFromJSON(str string) (ast.Node, error)

HclFromJSON converts a JSON string into an HCL ast.Node.

func HclListFromJSON

func HclListFromJSON(str string) (*ast.ListType, error)

HclListFromJSON the same as HclFromJSON but converts the result to a list.

func HclLiteralFromJSON

func HclLiteralFromJSON(str string) (*ast.LiteralType, error)

HclLiteralFromJSON the same as HclFromJSON but converts the result to a literal value.

Types

type HclDocument

type HclDocument struct {
	FileNode *ast.File
}

HclDocument represents an HCL document in memory.

func FromFile

func FromFile(filename string) (*HclDocument, error)

FromFile creates a new document from a file.

func FromReader

func FromReader(reader io.Reader) (*HclDocument, error)

FromReader creates a new document from an io.Reader

func (*HclDocument) Get

func (doc *HclDocument) Get(q string) (interface{}, error)

Get performs a query and returns a deserialized value. The query string is the same format as the command line.

func (*HclDocument) GetAsInt

func (doc *HclDocument) GetAsInt(q string) (int, error)

GetAsInt performs Get but converts the result to a string

func (*HclDocument) GetAsIntList

func (doc *HclDocument) GetAsIntList(q string) ([]int, error)

GetAsIntList does the same as GetAsList but with all values converted to ints. Returns an error if a value is found that is not an int and couldn't be parsed into one.

func (*HclDocument) GetAsList

func (doc *HclDocument) GetAsList(q string) ([]interface{}, error)

GetAsList does the same as Get but converts it to a list for you (with type check)

func (*HclDocument) GetAsString

func (doc *HclDocument) GetAsString(q string) (string, error)

GetAsString performs Get but converts the result to a string

func (*HclDocument) GetAsStringList

func (doc *HclDocument) GetAsStringList(q string) ([]string, error)

GetAsStringList does the same as GetAsList but converts everything to a string for you.

func (*HclDocument) GetKeys

func (doc *HclDocument) GetKeys(q string) ([]string, error)

GetKeys peforms a query and returns just the key or keys, no values.

func (*HclDocument) Print

func (doc *HclDocument) Print(writer io.Writer) error

Print writes the HCL document out to the given io.Writer.

func (*HclDocument) Query

func (doc *HclDocument) Query(queryString string) (results []Result, err error)

Query performs a generic query and returns matching results

func (*HclDocument) QueryKeys

func (doc *HclDocument) QueryKeys(queryString string) (keys []string, err error)

QueryKeys performs a query and returns matching key or keys, no values.

func (*HclDocument) Set

func (doc *HclDocument) Set(queryString string, listAction func(*ast.ListType) error, valueAction func(*token.Token) error) error

Set traverses the document and calls either listAction or valueAction depending on whether or not the value is a list or a literal value. These functions will be invoked for ALL matching nodes in the query.

type Result

type Result struct {
	Key   string
	Value interface{}
	Node  ast.Node
}

Result represents a query result

Jump to

Keyboard shortcuts

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