mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-24 12:46:38 +00:00
0884f89431
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
40 lines
892 B
Go
40 lines
892 B
Go
package hcl
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl/hcl/ast"
|
|
hclParser "github.com/hashicorp/hcl/hcl/parser"
|
|
jsonParser "github.com/hashicorp/hcl/json/parser"
|
|
)
|
|
|
|
// ParseBytes accepts as input byte slice and returns ast tree.
|
|
//
|
|
// Input can be either JSON or HCL
|
|
func ParseBytes(in []byte) (*ast.File, error) {
|
|
return parse(in)
|
|
}
|
|
|
|
// ParseString accepts input as a string and returns ast tree.
|
|
func ParseString(input string) (*ast.File, error) {
|
|
return parse([]byte(input))
|
|
}
|
|
|
|
func parse(in []byte) (*ast.File, error) {
|
|
switch lexMode(in) {
|
|
case lexModeHcl:
|
|
return hclParser.Parse(in)
|
|
case lexModeJson:
|
|
return jsonParser.Parse(in)
|
|
}
|
|
|
|
return nil, fmt.Errorf("unknown config format")
|
|
}
|
|
|
|
// Parse parses the given input and returns the root object.
|
|
//
|
|
// The input format can be either HCL or JSON.
|
|
func Parse(input string) (*ast.File, error) {
|
|
return parse([]byte(input))
|
|
}
|