bkl

package module
v1.0.53 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

README

bkl

bkl (short for Baklava because it has layers) is a templating configuration language without the templates. It's designed to be simple to read and write with obvious behavior.

Write your configuration in your favorite format: JSON, YAML, or TOML. Layer configurations on top of each other, even from different file formats. Use filenames to define the inheritance. Have as many layers as you like. bkl merges your layers together with sane default behavior that you can override. Export your results in any supported format for human or machine consumption. Use the CLI directly or in scripts or automate with the library.

Go Reference

Example

service.yaml
addr: 127.0.0.1
name: myService
port: 8080
service.test.toml
port = 8081
Run it!
$ bkl service.test.toml
addr = '127.0.0.1'
name = 'myService'
port = 8081

bkl knows that service.test.toml inherits from service.yaml by the filename pattern (override with $parent) and uses filename extensions to determine formats.

Install

$ go install github.com/gopatchy/bkl/...@latest

Verify that ~/go/bin is in your $PATH.

You can also download binaries directly here.

Documentation

Overview

Package bkl implements a layered configuration language parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountKeywordMatches added in v1.0.53

func CountKeywordMatches(text string, keywords []string) int

func Diff added in v1.0.52

func Diff(fx fs.FS, srcPath, dstPath string, rootPath string, workingDir string, selectors []string, format *string, paths ...*string) ([]byte, error)

func Evaluate added in v1.0.52

func Evaluate(fx fs.FS, files []string, rootPath string, workingDir string, env map[string]string, format *string, sort []string, paths ...*string) ([]byte, error)

Evaluate processes the specified files and returns the formatted output. If format is nil, it infers the format from the paths parameter (output path first, then input files). If env is nil, it uses the current OS environment.

func FormatOutput added in v1.0.52

func FormatOutput(data any, format *string, paths ...*string) ([]byte, error)

FormatOutput marshals the given data to the specified format. If format is nil or points to an empty string, it looks at the provided paths and uses the file extension of the first non-nil path as the format. Returns the marshaled bytes or an error if the format is unknown or marshaling fails.

func GetAllTests added in v1.0.53

func GetAllTests() (map[string]*DocExample, error)

func GetTests added in v1.0.52

func GetTests() (map[string]*DocExample, error)

func Intersect added in v1.0.52

func Intersect(fx fs.FS, paths []string, rootPath string, workingDir string, selectors []string, format *string, formatPaths ...*string) ([]byte, error)

func Required added in v1.0.52

func Required(fx fs.FS, path string, rootPath string, workingDir string, format *string, paths ...*string) ([]byte, error)

Required loads a file and returns only the required fields and their ancestors. It processes all documents in the file, outputting one document for each input document. The file is loaded directly without processing, matching bklr behavior. If format is nil, it infers the format from the paths parameter.

Types

type CompareResult added in v1.0.52

type CompareResult struct {
	File1       string
	File2       string
	Format      string
	Diff        string
	Environment map[string]string
	Sort        []string
}

func Compare added in v1.0.52

func Compare(fsys fs.FS, file1, file2 string, rootPath, workingDir string, env map[string]string, format *string, sort []string) (*CompareResult, error)

type DocCompare added in v1.0.53

type DocCompare struct {
	Left   DocLayer          `yaml:"left" json:"left" toml:"left"`
	Right  DocLayer          `yaml:"right" json:"right" toml:"right"`
	Result DocLayer          `yaml:"result" json:"result" toml:"result"`
	Env    map[string]string `yaml:"env,omitempty" json:"env,omitempty" toml:"env,omitempty"`
	Sort   []string          `yaml:"sort,omitempty" json:"sort,omitempty" toml:"sort,omitempty"`
}

func (*DocCompare) ConvertCodeBlocks added in v1.0.53

func (dc *DocCompare) ConvertCodeBlocks(targetFormat string) bool

func (*DocCompare) Score added in v1.0.53

func (dc *DocCompare) Score(keywords []string) int

type DocConvert added in v1.0.53

type DocConvert struct {
	From DocLayer `yaml:"from" json:"from"`
	To   DocLayer `yaml:"to" json:"to"`
}

func (*DocConvert) ConvertCodeBlocks added in v1.0.53

func (dc *DocConvert) ConvertCodeBlocks(targetFormat string) bool

func (*DocConvert) Score added in v1.0.53

func (dc *DocConvert) Score(keywords []string) int

type DocDiff added in v1.0.53

type DocDiff struct {
	Base     DocLayer `yaml:"base" json:"base" toml:"base"`
	Target   DocLayer `yaml:"target" json:"target" toml:"target"`
	Result   DocLayer `yaml:"result" json:"result" toml:"result"`
	Selector []string `yaml:"selector,omitempty" json:"selector,omitempty" toml:"selector,omitempty"`
	Errors   []string `yaml:"errors,omitempty" json:"errors,omitempty" toml:"errors,omitempty"`
}

func (*DocDiff) ConvertCodeBlocks added in v1.0.53

func (dd *DocDiff) ConvertCodeBlocks(targetFormat string) bool

func (*DocDiff) Score added in v1.0.53

func (dd *DocDiff) Score(keywords []string) int

type DocEvaluate added in v1.0.53

type DocEvaluate struct {
	Inputs []*DocLayer       `yaml:"inputs" json:"inputs" toml:"inputs"`
	Result DocLayer          `yaml:"result" json:"result" toml:"result"`
	Env    map[string]string `yaml:"env,omitempty" json:"env,omitempty" toml:"env,omitempty"`
	Errors []string          `yaml:"errors,omitempty" json:"errors,omitempty" toml:"errors,omitempty"`
	Root   string            `yaml:"root,omitempty" json:"root,omitempty" toml:"root,omitempty"`
	Sort   []string          `yaml:"sort,omitempty" json:"sort,omitempty" toml:"sort,omitempty"`
}

func (*DocEvaluate) ConvertCodeBlocks added in v1.0.53

func (de *DocEvaluate) ConvertCodeBlocks(targetFormat string) bool

func (*DocEvaluate) Score added in v1.0.53

func (de *DocEvaluate) Score(keywords []string) int

type DocExample added in v1.0.52

type DocExample struct {
	Description string        `toml:"description" json:"description" yaml:"description,omitempty"`
	Evaluate    *DocEvaluate  `yaml:"evaluate,omitempty" json:"evaluate,omitempty" toml:"evaluate,omitempty"`
	Diff        *DocDiff      `yaml:"diff,omitempty" json:"diff,omitempty" toml:"diff,omitempty"`
	Intersect   *DocIntersect `yaml:"intersect,omitempty" json:"intersect,omitempty" toml:"intersect,omitempty"`
	Required    *DocRequired  `yaml:"required,omitempty" json:"required,omitempty" toml:"required,omitempty"`
	Convert     *DocConvert   `yaml:"convert,omitempty" json:"convert,omitempty" toml:"convert,omitempty"`
	Fixit       *DocFixit     `yaml:"fixit,omitempty" json:"fixit,omitempty" toml:"fixit,omitempty"`
	Compare     *DocCompare   `yaml:"compare,omitempty" json:"compare,omitempty" toml:"compare,omitempty"`
	Benchmark   bool          `toml:"benchmark,omitempty" json:"benchmark,omitempty" yaml:"benchmark,omitempty"`
}

func (*DocExample) ConvertCodeBlocks added in v1.0.53

func (de *DocExample) ConvertCodeBlocks(targetFormat string) bool

func (*DocExample) Score added in v1.0.53

func (de *DocExample) Score(keywords []string) int

type DocFixit added in v1.0.53

type DocFixit struct {
	Original DocLayer `yaml:"original,omitempty" json:"original,omitempty"`
	Bad      DocLayer `yaml:"bad" json:"bad"`
	Good     DocLayer `yaml:"good" json:"good"`
}

func (*DocFixit) ConvertCodeBlocks added in v1.0.53

func (df *DocFixit) ConvertCodeBlocks(targetFormat string) bool

func (*DocFixit) Score added in v1.0.53

func (df *DocFixit) Score(keywords []string) int

type DocIntersect added in v1.0.53

type DocIntersect struct {
	Inputs   []*DocLayer `yaml:"inputs" json:"inputs" toml:"inputs"`
	Result   DocLayer    `yaml:"result" json:"result" toml:"result"`
	Selector []string    `yaml:"selector,omitempty" json:"selector,omitempty" toml:"selector,omitempty"`
	Errors   []string    `yaml:"errors,omitempty" json:"errors,omitempty" toml:"errors,omitempty"`
}

func (*DocIntersect) ConvertCodeBlocks added in v1.0.53

func (di *DocIntersect) ConvertCodeBlocks(targetFormat string) bool

func (*DocIntersect) Score added in v1.0.53

func (di *DocIntersect) Score(keywords []string) int

type DocItem added in v1.0.52

type DocItem struct {
	Content    string         `yaml:"content,omitempty" json:"content,omitempty"`
	Example    *DocExample    `yaml:"example,omitempty" json:"example,omitempty"`
	Code       *DocLayer      `yaml:"code,omitempty" json:"code,omitempty"`
	SideBySide *DocSideBySide `yaml:"side_by_side,omitempty" json:"side_by_side,omitempty"`
}

func (*DocItem) Score added in v1.0.53

func (di *DocItem) Score(keywords []string) int

type DocLayer added in v1.0.52

type DocLayer struct {
	Label      string   `yaml:"label,omitempty" json:"label,omitempty" toml:"label,omitempty"`
	Filename   string   `yaml:"filename,omitempty" json:"filename,omitempty" toml:"filename,omitempty"`
	Code       string   `yaml:"code" json:"code" toml:"code"`
	Content    string   `yaml:"content,omitempty" json:"content,omitempty" toml:"content,omitempty"`
	Highlights []string `yaml:"highlights,omitempty" json:"highlights,omitempty" toml:"highlights,omitempty"`
	Languages  [][]any  `yaml:"languages,omitempty" json:"languages,omitempty" toml:"languages,omitempty"`
	Expandable bool     `yaml:"expandable,omitempty" json:"expandable,omitempty" toml:"expandable,omitempty"`
	Collapsed  bool     `yaml:"collapsed,omitempty" json:"collapsed,omitempty" toml:"collapsed,omitempty"`
}

func (*DocLayer) ConvertCodeBlocks added in v1.0.53

func (dl *DocLayer) ConvertCodeBlocks(targetFormat string) bool

func (*DocLayer) Score added in v1.0.53

func (dl *DocLayer) Score(keywords []string) int

type DocRequired added in v1.0.53

type DocRequired struct {
	Inputs []*DocLayer       `yaml:"inputs" json:"inputs" toml:"inputs"`
	Result DocLayer          `yaml:"result" json:"result" toml:"result"`
	Env    map[string]string `yaml:"env,omitempty" json:"env,omitempty" toml:"env,omitempty"`
	Errors []string          `yaml:"errors,omitempty" json:"errors,omitempty" toml:"errors,omitempty"`
	Root   string            `yaml:"root,omitempty" json:"root,omitempty" toml:"root,omitempty"`
}

func (*DocRequired) ConvertCodeBlocks added in v1.0.53

func (dr *DocRequired) ConvertCodeBlocks(targetFormat string) bool

func (*DocRequired) Score added in v1.0.53

func (dr *DocRequired) Score(keywords []string) int

type DocSection added in v1.0.52

type DocSection struct {
	ID     string    `yaml:"id" json:"id"`
	Title  string    `yaml:"title" json:"title"`
	Items  []DocItem `yaml:"items" json:"items"`
	Source string    `yaml:"-" json:"-"`
}

func GetDocSections added in v1.0.52

func GetDocSections() ([]DocSection, error)

func (*DocSection) ConvertCodeBlocks added in v1.0.53

func (ds *DocSection) ConvertCodeBlocks(targetFormat string) bool

func (*DocSection) Score added in v1.0.53

func (ds *DocSection) Score(keywords []string) int

type DocSideBySide added in v1.0.52

type DocSideBySide struct {
	Left  DocLayer `yaml:"left" json:"left"`
	Right DocLayer `yaml:"right" json:"right"`
}

func (*DocSideBySide) Score added in v1.0.53

func (ds *DocSideBySide) Score(keywords []string) int

type TreeResult added in v1.0.52

type TreeResult struct {
	Path   string `json:"path"`
	Error  error  `json:"error,omitempty"`
	Output string `json:"output,omitempty"`
}

func EvaluateTree added in v1.0.52

func EvaluateTree(fx fs.FS, directory string, pattern string, env map[string]string, format *string) ([]TreeResult, error)

Directories

Path Synopsis
cmd
bkl command
bkl-mcp command
bklb command
bklc command
bkld command
bkli command
bklr command
kubectl-bkl command
internal
pkg
log

Jump to

Keyboard shortcuts

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