parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Envsubst

func Envsubst(p *Parser) error

Envsubst enables replacing ${var} or $var with their environment values.

Types

type File

type File struct {
	BaseDir string
	Path    []string
}

File holds a file's metadata.

func (File) Dir

func (f File) Dir() string

Dir returns the base directory of a file.

func (File) FullPath

func (f File) FullPath() string

FullPath joins base directory with all path segments.

type Mode added in v0.4.0

type Mode int

Mode is the type of configuration. Each configuration has a distinct base directory.

const (
	// UserMode refers to the default user configuration directory.
	UserMode Mode = iota
	// HomeMode refers to the home directory.
	HomeMode
)

type Node

type Node struct {
	Target   File
	Link     File
	Children []*Node
	Status   Status
}

Node is a tree node that holds nested file metadata.

type ParseOption

type ParseOption func(*Parser) error

ParseOption is a funcional option that intend to modify a Parser.

func BaseDirs added in v0.4.0

func BaseDirs(dirs map[Mode]string) ParseOption

func Cwd

func Cwd(dirname string) ParseOption

Cwd sets a common cwd for targets.

func Tags added in v0.5.0

func Tags(tags map[string]struct{}) ParseOption

Tags filters targets by their tags.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is a configuration parser.

func (*Parser) Parse

func (p *Parser) Parse(c *config.Config, opts ...ParseOption) (*Tree, error)

Parse parses a configuration file and returns its tree representation.

type Status

type Status uint8

Status is a node's status.

const (
	// StatusReady means the node is ready to be symlinked.
	StatusReady Status = 1 << iota
	// StatusSkip means the node has children and thus might be skipped.
	StatusSkip
	// StatusDone means the symlink already exists and is pointing exactly
	// to the specified node.
	StatusDone
	// StatusConflict means a symlink already exists but points to a different target.
	StatusConflict
	// StatusError means the target doesn't exist.
	StatusError
	// StatusExpand means a symlink already exists but since it's a directory
	// and the target is also a directory, it gets expanded in order to have
	// the target's inner files symlinked inside it.
	StatusExpand
)

func (Status) String

func (s Status) String() string

type Tree

type Tree struct {
	Root *Node
}

Tree is a simple tree data structure that holds parsed configuration data.

func (*Tree) String

func (tr *Tree) String() string

func (*Tree) Walk

func (tr *Tree) Walk(fn func(*Node) error) error

Walk traverses the tree using depth-first search and runs fn for each node found.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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