gen

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: BSD-3-Clause Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const CUE_VENDOR_DIR = "./cue.mod/pkg/"
View Source
const SHADOW_DIR = ".hof/shadow/"

Variables

This section is empty.

Functions

func Gen added in v0.6.0

func Gen(args []string, cmdflags flags.GenFlagpole) error

func LoadShadow

func LoadShadow(subdir string, verbose bool) (map[string]*File, error)

Types

type File

type File struct {
	// Input Data, local to this file
	In map[string]interface{}

	// The full path under the output location
	// empty implies don't generate, even though it may endup in the list
	Filepath string

	// Template parameters (only one should be set at a time i.e. != "")
	TemplateContent string // The content, takes precedence over next option
	TemplatePath    string // Named template
	DatafileFormat  string // Data format file

	// Template delimiters
	TemplateDelims *templates.Delims

	// CUE value for datafiles
	// (we use a different name here so that it does not automatically try to decode, which would require concreteness)
	Value cue.Value

	// Generator that owns this file
	// TODO, does this break with the multi-generator hack?
	//       or is this the behavior defined by the way generators are included together
	//       because the user will be able to do it both ways, the hack doesn't to away,
	// there's just a more recommended way to do it
	Gen *Generator

	// Template Instance Pointer
	//   If local, this will be created when the template content is laoded
	//   If a named template, acutal template lives in the generator and is created at folder import time
	TemplateInstance *templates.Template

	// Content
	RenderContent []byte
	FinalContent  []byte

	// Shadow related
	ShadowFile *File
	UserFile   *File

	DoWrite bool

	// Bookkeeping
	Errors []error
	FileStats
}

func (*File) FormatRendered

func (F *File) FormatRendered() error

func (*File) ReadShadow

func (F *File) ReadShadow() error

func (*File) ReadUser

func (F *File) ReadUser() error

func (*File) Render

func (F *File) Render(shadow_basedir string) error

func (*File) RenderData added in v0.6.1

func (F *File) RenderData() (err error)

func (*File) RenderTemplate

func (F *File) RenderTemplate() (err error)

func (*File) UnifyContent

func (F *File) UnifyContent() (write bool, err error)

func (*File) WriteOutput

func (F *File) WriteOutput() error

func (*File) WriteShadow

func (F *File) WriteShadow(basedir string) error

type FileStats

type FileStats struct {
	// using 0 (false) and 1 (true) for easier summation code below
	IsNew     int
	IsSame    int
	IsSkipped int
	IsWritten int
	IsErr     int

	IsModified       int
	IsModifiedRender int
	IsModifiedOutput int
	IsModifiedDiff3  int
	IsConflicted     int

	RenderingTime time.Duration
	CompareTime   time.Duration
	TotalTime     time.Duration
}

type Generator

type Generator struct {
	//
	// Set by Hof via cuelang extraction
	// Label in Cuelang
	Name string

	// Base directory for output
	Outdir string

	// "Global" input, merged with out replacing onto the files
	In  map[string]interface{}
	Val cue.Value

	// The list fo files for hof to generate, in cue values
	Out []*File

	Templates []*TemplateGlobs
	Partials  []*TemplateGlobs

	// Filepath globs for static files to load
	Statics []*StaticGlobs

	// The following will be automatically added to the template context
	// under its name for reference in GenFiles  and partials in templates
	EmbeddedTemplates map[string]*TemplateContent
	EmbeddedPartials  map[string]*TemplateContent

	// Static files are available for pure cue generators that want to have static files
	// These should be named by their filepath, but be the content of the file
	EmbeddedStatics map[string]string

	// Subgenerators for composition
	Generators map[string]*Generator

	// Used for indexing into the vendor directory...
	PackageName string

	// Disabled? we do this when looking at expressions and optimizing
	// TODO, make this field available in cuelang?
	Disabled bool

	// Template System Cache
	TemplateMap templates.TemplateMap
	PartialsMap templates.TemplateMap

	// Files and the shadow dir for doing neat things
	Files  map[string]*File
	Shadow map[string]*File

	// Print extra information
	Debug bool

	// Status for this generator and processing
	Stats *GeneratorStats

	// Cuelang related, also set externally
	CueValue cue.Value
}

A generator pulled from the cue instances

func NewGenerator

func NewGenerator(label string, value cue.Value) *Generator

func (*Generator) GenerateFiles

func (G *Generator) GenerateFiles() []error

func (*Generator) Initialize added in v0.2.9

func (G *Generator) Initialize() []error

func (*Generator) LoadCue

func (G *Generator) LoadCue() (errs []error)

func (*Generator) ResolveFile added in v0.2.9

func (G *Generator) ResolveFile(F *File) error

type GeneratorStats

type GeneratorStats struct {
	NumNew     int
	NumSame    int
	NumSkipped int
	NumDeleted int
	NumWritten int
	NumStatic  int
	NumErr     int
	TotalFiles int

	NumModified       int
	NumModifiedRender int
	NumModifiedOutput int
	NumModifiedDiff3  int
	NumConflicted     int

	LoadingTime   time.Duration
	RenderingTime time.Duration
	WritingTime   time.Duration
	TotalTime     time.Duration
}

func (*GeneratorStats) CalcTotals

func (S *GeneratorStats) CalcTotals(G *Generator) error

func (*GeneratorStats) String

func (S *GeneratorStats) String() string

type Runtime added in v0.6.0

type Runtime struct {
	// Setup options
	Entrypoints []string
	Flagpole    flags.GenFlagpole

	// Cue ralated
	CueCTX          *cue.Context
	BuildInstances  []*build.Instance
	CueInstances    []*cue.Instance
	TopLevelValues  []cue.Value
	TopLevelStructs []*cue.Struct

	// Hof related
	Generators map[string]*Generator
	Shadow     map[string]*File
	Stats      *RuntimeStats
	// contains filtered or unexported fields
}

func NewRuntime added in v0.6.0

func NewRuntime(entrypoints []string, cmdflags flags.GenFlagpole) *Runtime

func (*Runtime) ExtractGenerators added in v0.6.0

func (R *Runtime) ExtractGenerators()

func (*Runtime) LoadCue added in v0.6.0

func (R *Runtime) LoadCue() []error

func (*Runtime) LoadGenerators added in v0.6.0

func (R *Runtime) LoadGenerators() []error

func (*Runtime) PrintMergeConflicts added in v0.6.0

func (R *Runtime) PrintMergeConflicts()

func (*Runtime) PrintStats added in v0.6.0

func (R *Runtime) PrintStats()

func (*Runtime) RunGenerator added in v0.6.0

func (R *Runtime) RunGenerator(G *Generator) (errs []error)

func (*Runtime) RunGenerators added in v0.6.0

func (R *Runtime) RunGenerators() []error

func (*Runtime) WriteGenerator added in v0.6.0

func (R *Runtime) WriteGenerator(G *Generator) (errs []error)

func (*Runtime) WriteOutput added in v0.6.0

func (R *Runtime) WriteOutput() []error

type RuntimeStats added in v0.6.1

type RuntimeStats struct {
	CueLoadingTime time.Duration
	GenLoadingTime time.Duration
	GenRunningTime time.Duration
}

func (*RuntimeStats) String added in v0.6.1

func (S *RuntimeStats) String() string

type StaticGlobs added in v0.6.0

type StaticGlobs struct {
	// Globs to load
	Globs []string
	// Prefix to trim
	TrimPrefix string
	// Prefix to add before output
	OutPrefix string
}

type TemplateContent added in v0.6.0

type TemplateContent struct {
	Content string
	Delims  *templates.Delims
}

type TemplateGlobs added in v0.6.0

type TemplateGlobs struct {
	// Globs to load
	Globs []string
	// Prefix to trim
	TrimPrefix string
	// Custom delims
	Delims *templates.Delims
}

Jump to

Keyboard shortcuts

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