exec

package
v0.0.0-...-4064bea Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package exec implements boil's exec command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(config *Config) (err error)

Run executes the Exec command configured by config. If an error occurs it is returned and the operation may be considered failed.

Types

type Config

type Config struct {
	// TemplatePath is the source template path. During Run() it is adjusted to
	// an absolute path to the Template either inside or outside of repository.
	//
	// If the path is rooted, i.e. starts with "/" the path is treated as an
	// absolute path to a Template and no repository is being loaded or used.
	//
	// If the path is not rooted, the path is treated as a path to a Template
	// relative to the loaded repository.
	//
	// If TemplatePath is an absolute filesystem path it is adjusted to an
	// empty string during Run().
	TemplatePath string

	// OutputDir is the output directory where Template will be executed.
	// If the value is empty the Template will be executed in the current
	// working directory
	//
	// TargetPath is adjusted to an absolute path of OutputDir during Run().
	OutputDir string

	// Overwrite, if true specifies that any file matching a Template output
	// file already existing in the target directory may be overwritten without
	// prompting the user or generating an error.
	Overwrite bool

	// NoExecute if true will not execute any write operations and will
	// instead print out the operations like boil.Config.Verbose was enabled.
	NoExecute bool

	// NoPrompts if true disables prompting the user for variables and will
	// return an error if a variable declared in a prompt was not parsed from
	// the command line.
	NoPrompts bool

	// NoMetadata if true disables parsing template metadata and copies the
	// source template files recursively to output directory. This disables
	// groups and prompts but the variable system still works via command line.
	NoMetadata bool

	// EditAfterExec if true opens the output with the editor.
	EditAfterExec bool

	// GoInputs is a list of paths of go files or packages to parse and make
	// their AST available to template files.
	GoInputs []string

	// JsonInputs is a list of paths of json files to parse and make available
	// to template files.
	JsonInputs []string

	// Vars are variables given by the user on command line.
	// These variables will be available via .Vars template field.
	Vars boil.Variables

	// Config is the loaded program configuration.
	Config *boil.Config
}

Config is the Exec command configuration.

func (*Config) GetRepositoryPath

func (self *Config) GetRepositoryPath() string

GetRepositoryPath returns the RepositoryPath considering override values.

func (*Config) ShouldPrint

func (self *Config) ShouldPrint() bool

ShouldPrint returns true if Config.Verbose or Config.NoExecute is true.

type Execute

type Execute struct {
	// Path is the path to the template directory relative to repository root.
	Path string
	// Source is path of the template file or dir relative to repo root.
	Source string
	// Target is the absolute path of the target file which will contain Source
	// template output. If the source path had placeholder values they will be
	// replaced with actual values to generate output filenames.
	Target string
	// IsDir wil be true if Source is a directory.
	IsDir bool
}

Execute defines an execution action as part of a exec command task.

type PresentPromptFunc

type PresentPromptFunc = func(p *boil.Prompt) (def string, present bool)

type Task

type Task struct {
	// Metafile is the Template Metafile.
	Metafile *boil.Metafile
	// List is a list of actions to be performed for this template.
	List []*Execute
}

Task defines an execution task to perform for a template.

type Tasks

type Tasks []*Task

Tasks is a list of Task.

func (Tasks) CheckForTargetConflicts

func (self Tasks) CheckForTargetConflicts() (err error)

CheckForTargetConflicts returns nil if none of the Target paths of all defined Tasks in self do not point to an existing file. Otherwise a descriptive error is returned.

func (Tasks) ExecPostExecuteActions

func (self Tasks) ExecPostExecuteActions(data *boil.Data) (err error)

ExecPostExecuteActions executes all PostExecute actions defined in all metafiles in the order they are defined, depth first. The first error that occurs from any action is returned and execution stopped or nil if everything successed.

func (Tasks) ExecPreExecuteActions

func (self Tasks) ExecPreExecuteActions(data *boil.Data) (err error)

ExecPreExecuteActions executes all PreExecute actions defined in all metafiles in the order they are defined, depth first. The first error that occurs from any action is returned and execution stopped or nil if everything successed.

func (Tasks) ExecPreParseActions

func (self Tasks) ExecPreParseActions() (err error)

ExecPreParseActions executes all PreParse actions defined in all metafiles in the order they are defined, depth first. The first error that occurs from any action is returned and execution stopped or nil if everything successed.

func (Tasks) Execute

func (self Tasks) Execute(state *state, print bool) (err error)

Execute executes all tasks in self or returns an error.

func (Tasks) PresentPrompts

func (self Tasks) PresentPrompts(state *state, cb PresentPromptFunc) (err error)

PresentPrompts presents a prompt to the user on command line for each of the prompts defined in metafiles of all tasks in self, in order as they appear in self, depth first. If undeclaredOnly is true only prompts for entries not found in variables are presented.

Values are stored in variables under names of Variables they prompt for. If undeclaredOnly is true, a variable already defined in variables will not be prompted for.

func (Tasks) Print

func (self Tasks) Print(wr io.Writer)

Print prints self to stdout.

func (Tasks) SetTargetsFromState

func (self Tasks) SetTargetsFromState(state *state) (err error)

SetTargetsFromState expands template tokens in each execution.Target of self and determines the absolute path of each in the output directory. Returns an error if one occurs or nil.

func (Tasks) Validate

func (self Tasks) Validate(state *state) (err error)

Validate calls Validate on metafiles of each metafile loaded by each Task in self. It returns the first validation error that occurs or nil if all passed.

Jump to

Keyboard shortcuts

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