mktree

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 17 Imported by: 0

README

mktree

PkgGoDev

An s-expression based configuration language for generating boilerplate directories and files.

For documentation see kendalhar.land/mktree

Documentation

Overview

Package mktree implements a language for generating boilerplate files and directories.

Example (Dir)
interpret(`(dir "test")`)
Output:

drwxrwxrwx [example]
drwxrwxrwx [example]/test
Example (File)
interpret(`(file "test")`)
Output:

drwxrwxrwx [example]
-rw-rw-rw- [example]/test 0
Example (Parent_dirs)
interpret(`(file "/a/b/c/d/e.txt")`)
Output:

drwxrwxrwx [example]
-rw-rw-rw- [example]/a/b/c/d/e.txt 0
Example (Perms)
interpret(`
	(dir "a" (@perms 0700))
	(file "b" (@perms 0755))
	`)
Output:

drwxrwxrwx [example]
drwx------ [example]/a
-rwxr-xr-x [example]/b 0
Example (Tree_with_perms)
interpret(`
	(dir "a" 
		(@perms 0700)
		(file "b"
			(@perms 0755)))
	`)
Output:

drwxrwxrwx [example]
drwx------ [example]/a
-rwxr-xr-x [example]/a/b 0
Example (Vars)
interpretVars(`
	(dir "%(dirname)" (@perms %(perms)))
	(file "%(filename)" (@perms %(perms)))
	(dir "%(root_dir)")
	`, map[string]string{
	"dirname":  "a",
	"filename": "b.txt",
	"perms":    "0555",
})
Output:

drwxrwxrwx [example]
dr-xr-xr-x [example]/a
drwxrwxrwx [example]/[example]
-r-xr-xr-x [example]/b.txt 0

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInterpret = errors.New("interpet error")

Functions

func Version

func Version() string

Version returns the current version of this package.

Types

type Dir

type Dir struct {
	Name  string
	Perms os.FileMode
	Files []*File
	Dirs  []*Dir
}

func (*Dir) DebugPrint added in v1.1.0

func (d *Dir) DebugPrint(w io.Writer)

type File

type File struct {
	Name             string
	Perms            os.FileMode
	Contents         []byte
	TemplateFilename string
}

func (*File) DebugPrint added in v1.1.0

func (f *File) DebugPrint(w io.Writer)

type Interpreter

type Interpreter struct {
	Root               string
	Vars               map[string]string
	AllowUndefinedVars bool
	Stderr             io.Writer
}

func (*Interpreter) ExecFile added in v1.1.0

func (i *Interpreter) ExecFile(filename string, opts ...Option) error

func (*Interpreter) Interpret

func (i *Interpreter) Interpret(r io.Reader) (*Tree, error)

type Option added in v1.1.0

type Option interface {
	// contains filtered or unexported methods
}

func WithTemplateFunction added in v1.1.0

func WithTemplateFunction(name string, f interface{}) Option

type Tree added in v1.1.0

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

func Interpret

func Interpret(r io.Reader) (*Tree, error)

func (*Tree) Create added in v1.1.0

func (t *Tree) Create(opts ...Option) error

func (*Tree) DebugPrint added in v1.1.0

func (t *Tree) DebugPrint(w io.Writer)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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