bkl

package module
v1.0.52 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: Apache-2.0 Imports: 21 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 Diff added in v1.0.52

func Diff(fx fs.FS, srcPath, dstPath string, rootPath string, workingDir string, selector 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, sortPath 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 GetTests added in v1.0.52

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

func Intersect added in v1.0.52

func Intersect(fx fs.FS, paths []string, rootPath string, workingDir string, selector 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
	SortPath    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, sortPath string) (*CompareResult, error)

type DocExample added in v1.0.52

type DocExample struct {
	Operation string     `yaml:"operation,omitempty"`
	Layers    []DocLayer `yaml:"layers,omitempty"`
	Result    DocLayer   `yaml:"result,omitempty"`
}

type DocItem added in v1.0.52

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

type DocLayer added in v1.0.52

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

type DocSection added in v1.0.52

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

func GetDocSections added in v1.0.52

func GetDocSections() ([]DocSection, error)

type DocSideBySide added in v1.0.52

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

type TestCase added in v1.0.52

type TestCase struct {
	Description string            `toml:"description"`
	Eval        []string          `toml:"eval"`
	Format      string            `toml:"format"`
	Expected    string            `toml:"expected,omitempty"`
	Files       map[string]string `toml:"files"`
	Errors      []string          `toml:"errors,omitempty"`
	RootPath    string            `toml:"rootPath,omitempty"`
	Env         map[string]string `toml:"env,omitempty"`
	Diff        bool              `toml:"diff,omitempty"`
	Intersect   bool              `toml:"intersect,omitempty"`
	Required    bool              `toml:"required,omitempty"`
	Compare     bool              `toml:"compare,omitempty"`
	Benchmark   bool              `toml:"benchmark,omitempty"`
	Selector    string            `toml:"selector,omitempty"`
	SortPath    string            `toml:"sortPath,omitempty"`
}

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