generator

package
v0.0.0-...-a4ecfcf Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommand

func AddCommand(parser *flags.Parser) error

AddCommand to the parser

func ExecValueTemplate

func ExecValueTemplate(value string, node *brief.Node) (string, error)

ExecValueTemplate for templates inside action key values

func ExecuteMacro

func ExecuteMacro(tmpl *template.Template, section *brief.Node) ([]*brief.Node, error)

ExecuteMacro template which defines a brief spec then decode into nodes

func MakeFolder

func MakeFolder(names ...string) error

MakeFolder from list of dir names

func MergeBody

func MergeBody(node, other *brief.Node)

MergeBody of two nodes, the left node takes precendence

func MergeKeys

func MergeKeys(node, other *brief.Node)

MergeKeys of two nodes, the left node takes precedence

func MergeNode

func MergeNode(node, other *brief.Node)

MergeNode combines two nodes recursively

func MergeNodes

func MergeNodes(body []*brief.Node, useNames bool) []*brief.Node

MergeNodes combine a set of nodes of the same Type useNames means they are only merged if they have the same name

func ReadNode

func ReadNode(specfile string) (*brief.Node, error)

ReadNode reads a single node from a brief file

func ValidateAction

func ValidateAction(act *brief.Node, pos int) error

ValidateAction ensure correct action node

func ValidateFolder

func ValidateFolder(name string) error

ValidateFolder ensures a folder exists and can be written

func ValidateTemplate

func ValidateTemplate(tmpl *brief.Node, pos int) error

ValidateTemplate ensure correct template node

Types

type Agenda

type Agenda struct {
	Templates *Dictionary
	Actions   *Dictionary
	Found     bool
}

Agenda contains steps to perform

func NewAgenda

func NewAgenda() *Agenda

NewAgenda constructor

func (*Agenda) AddAction

func (a *Agenda) AddAction(node *brief.Node)

AddAction add action to an agenda

func (*Agenda) AddTemplate

func (a *Agenda) AddTemplate(node *brief.Node)

AddTemplate add template to an agenda

type Catalog

type Catalog map[string]*Agenda

Catalog of agenda for elements in the spac

func (Catalog) Add

func (cat Catalog) Add(elem string) *Agenda

Add the agenda for an element

type Command

type Command struct {
	Args struct {
		SpecFile    string `positional-arg-name:"specfile" description:"brevity specification file"`
		Destination string `positional-arg-name:"destination" description:"where to put the project root folder"`
	} `positional-args:"true" required:"true"`
	Library string `short:"l" long:"lib" description:"Brevity library location" env:"BREVITY_LIB"`
	Render  bool   `short:"r" long:"render" description:"Render files without actions"`
	// contains filtered or unexported fields
}

Command for generate

func (*Command) CompileSection

func (cmd *Command) CompileSection(section *brief.Node) (*Generator, error)

CompileSection within a project Gather

func (*Command) Execute

func (cmd *Command) Execute(args []string) error

Execute the project command

func (*Command) ExpandProjectMacros

func (cmd *Command) ExpandProjectMacros(project *brief.Node) error

ExpandProjectMacros loops over project sections until all macros are expanded

func (*Command) Generate

func (cmd *Command) Generate(brevity *brief.Node) error

Generate brevity projects into a destination folder

func (*Command) New

func (cmd *Command) New() *Generator

New Generator ctor

func (*Command) Project

func (cmd *Command) Project(project *brief.Node) error

Project generates nth project in the spec

func (*Command) ReadSpec

func (cmd *Command) ReadSpec() (*brief.Node, error)

ReadSpec brevity spec from file

type Dictionary

type Dictionary struct {
	Map  map[string]*brief.Node
	List []*brief.Node
}

Dictionary is used to index elements within a section

func NewDictionary

func NewDictionary() *Dictionary

NewDictionary construct empty dictionary

func (*Dictionary) Add

func (dict *Dictionary) Add(node *brief.Node)

Add node to a dictionary

type FileSet

type FileSet struct {
	Err error
	// contains filtered or unexported fields
}

FileSet set of files for finding recursion

func NewFileSet

func NewFileSet() *FileSet

NewFileSet constructor

func (*FileSet) Add

func (fset *FileSet) Add(file string) *FileSet

Add a file to the fileset

func (*FileSet) ReverseFiles

func (fset *FileSet) ReverseFiles() []string

ReverseFiles files found in reverse order

type Generator

type Generator struct {
	Catalog         Catalog
	Template        *template.Template
	Render          bool
	LibDir, SpecDir string
}

Generator for code

func (*Generator) ApplyActions

func (gtor *Generator) ApplyActions(spec *brief.Node, dir string) error

ApplyActions executes actions for this spec node

func (*Generator) ApplyTemplates

func (gtor *Generator) ApplyTemplates(spec *brief.Node, dir string) error

ApplyTemplates executes templates for this spec node

func (*Generator) ExecAction

func (gtor *Generator) ExecAction(action, spec *brief.Node, dir string) error

ExecAction executes an action

func (*Generator) GenFile

func (gtor *Generator) GenFile(action, spec *brief.Node, dir string) error

GenFile generates a file from a template

func (*Generator) LoadGenerator

func (gtor *Generator) LoadGenerator(genfile string) error

LoadGenerator if the genfile exists

func (*Generator) LoadGlobTemplates

func (gtor *Generator) LoadGlobTemplates(fileglob string) error

LoadGlobTemplates loads templates from the fileglob into generator

func (*Generator) LoadSectionTemplates

func (gtor *Generator) LoadSectionTemplates(section *brief.Node) error

LoadSectionTemplates load templates for a section

func (*Generator) NextNode

func (gtor *Generator) NextNode(node *brief.Node, dir string) error

NextNode recursively generates node hierarchy

func (*Generator) SectionNames

func (gtor *Generator) SectionNames(section *brief.Node) (map[string]bool, error)

SectionNames subdirs of the templates directory

func (*Generator) ValidateSection

func (gtor *Generator) ValidateSection(section *brief.Node) error

ValidateSection returns and error if any template elements are missing

Jump to

Keyboard shortcuts

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