Documentation ¶
Index ¶
- Constants
- Variables
- func CelCompileAndEval(ctx context.Context, scope *Scope, expr model.String, outPtr any) error
- func CopyRecursive(ctx context.Context, pos *model.ConfigPos, p *CopyParams) (outErr error)
- func IsReservedInDest(relPath string) bool
- func IsReservedStdout(relPath string) bool
- func IsStatNotExistErr(err error) bool
- func JoinIfRelative(cwd, path string) string
- func Run(ctx context.Context, args ...string) (stdout, stderr string, _ error)
- func RunMany(ctx context.Context, args ...[]string) (stdouts, stderrs []string, _ error)
- func SafeRelPath(pos *model.ConfigPos, p string) (string, error)
- type CopyHint
- type CopyParams
- type CopyVisitor
- type ErrorFS
- func (e *ErrorFS) MkdirAll(name string, mode fs.FileMode) error
- func (e *ErrorFS) Open(name string) (fs.File, error)
- func (e *ErrorFS) OpenFile(name string, flag int, mode os.FileMode) (*os.File, error)
- func (e *ErrorFS) ReadFile(name string) ([]byte, error)
- func (e *ErrorFS) RemoveAll(name string) error
- func (e *ErrorFS) Stat(name string) (fs.FileInfo, error)
- func (e *ErrorFS) WriteFile(name string, data []byte, perm os.FileMode) error
- type FS
- type RealFS
- func (r *RealFS) MkdirAll(name string, perm os.FileMode) error
- func (r *RealFS) MkdirTemp(dir, pattern string) (string, error)
- func (r *RealFS) Open(name string) (fs.File, error)
- func (r *RealFS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func (r *RealFS) ReadFile(name string) ([]byte, error)
- func (r *RealFS) RemoveAll(name string) error
- func (r *RealFS) Stat(name string) (fs.FileInfo, error)
- func (r *RealFS) WriteFile(name string, data []byte, perm os.FileMode) error
- type Scope
Constants ¶
const ( // Permission bits: rwx------ . OwnerRWXPerms = 0o700 // Permission bits: rw------- . OwnerRWPerms = 0o600 )
const ( ABCInternalDir = ".abc" ABCInternalStdout = "stdout" )
ABCInternalDir is the name for internal directories that have things like manifests and .gitkeep files. These may be destination directories or golden-test data/ directories.
const DefaultRunTimeout = time.Minute
DefaultRunTimeout is how long we'll wait for commands to run in the case where the context doesn't already have a timeout. This was chosen arbitrarily.
Variables ¶
var DoNotModifyHeader = []byte("# Generated by the \"abc templates\" command. Do not modify.\n")
Functions ¶
func CelCompileAndEval ¶
celCompileAndEval parses, compiles, and executes the given CEL expr with the given variables in scope.
The output of CEL execution is written into the location pointed to by outPtr. It must be a pointer. If the output of the CEL expression can't be converted to the given type, then an error will be returned. For example, if the CEL expression is "hello" and outPtr points to an int, an error will returned because CEL cannot treat "hello" as an integer.
func CopyRecursive ¶ added in v0.2.0
CopyRecursive recursively copies folder contents with designated config params.
func IsReservedInDest ¶ added in v0.6.0
IsReservedInDest returns true if the given path cannot be created in the destination directory because that name is reserved for internal purposes.
The input path must use the local OS separators, since we process it with filepath. This path is relative to the destination directory.
func IsReservedStdout ¶ added in v0.6.0
IsReservedStdout returns true if the given path is the internal stdout path.
The input path must use the local OS separators, since we process it with filepath. This path is relative to the destination directory.
func IsStatNotExistErr ¶ added in v0.4.0
IsStatNotExistErr takes an error returned by os.Stat() and returns true if the error means "the path you stat'ed doesn't exist." It otherwise returns false.
func JoinIfRelative ¶ added in v0.7.0
JoinIfRelative returns path if it's an absolute path, otherwise filepath.Join(cwd, path).
func Run ¶ added in v0.2.1
Run is a wrapper around exec.CommandContext and Run() that captures stdout and stderr as strings. The input args must have len>=1.
This is intended to be used for commands that run non-interactively then exit.
This doesn't execute a shell (unless of course args[0] is the name of a shell binary).
If the incoming context doesn't already have a timeout, then a default timeout will be added (see DefaultRunTimeout).
If the command fails, the error message will include the contents of stdout and stderr. This saves boilerplate in the caller.
func RunMany ¶ added in v0.4.0
RunMany calls Run for each command in args. If any command returns error, then no further commands will be run, and that error will be returned. For any commands that were actually executed (not aborted by a previous error), their stdout and stderr will be returned. It's guaranteed that len(stdouts)==len(stderrs).
Types ¶
type CopyHint ¶ added in v0.2.0
type CopyHint struct { // Before overwriting a file in the destination dir, copy the preexisting // contents of the file into ~/.abc/$timestamp. Only used if // overwrite==true. // // This has no effect on directories, only files. BackupIfExists bool // Overwrite files in the destination if they already exist. The default is // to conservatively fail. // // This has no effect on directories, only files. Overwrite bool // Whether to skip this file or directory (don't write it to the // destination). For directories, this will cause all files underneath the // directory to be skipped. Skip bool }
type CopyParams ¶ added in v0.2.0
type CopyParams struct { // backupDirMaker will be called when we reach the first file that actually // needs to be backed up. It should create a directory and return its path, // either relative to the cwd or absolute. Use os.MkdirTemp() in real code // and something hardcoded in tests. BackupDirMaker func(FS) (string, error) // // backupDir provides the path at which files will be saved before they're // // overwritten. // backupDir string // dryRun skips actually copy anything, just checks whether the copy would // be likely to succeed. DryRun bool // dstRoot is the output directory. May be absolute or relative. DstRoot string // srcRoot is the file or directory from which to copy. May be absolute or // relative. SrcRoot string // FS is the filesytem to use. FS FS // visitor is an optional function that will be called for each file in the // source, to allow customization of the copy operation on a per-file basis. Visitor CopyVisitor // If Hasher and OutHashes are not nil, then each copied file will be hashed // and the hex hash will be saved in OutHashes. If a file is "skipped" // (CopyHint.Skip==true) then the hash will not be computed. In dry run // mode, the hash will be computed normally. OutHashes always uses forward // slashes as path separator, regardless of OS. Hasher func() hash.Hash OutHashes map[string][]byte }
CopyParams contains most of the parameters to CopyRecursive(). There were too many of these, so they've been factored out into a struct to avoid having the function parameter list be really long.
type CopyVisitor ¶ added in v0.2.0
CopyVisitor is the type for callback functions that are called by CopyRecursive for each file and directory encountered. It gives the caller an opportunity to influence the behavior of the copy operation on a per-file basis, and also informs the of each file and directory being copied.
type ErrorFS ¶ added in v0.3.1
type ErrorFS struct { FS MkdirAllErr error OpenErr error OpenFileErr error ReadFileErr error RemoveAllErr error StatErr error WriteFileErr error }
A renderFS implementation that can inject errors for testing.
type FS ¶ added in v0.2.0
type FS interface { fs.StatFS // These methods correspond to methods in the "os" package of the same name. MkdirAll(string, os.FileMode) error MkdirTemp(string, string) (string, error) OpenFile(string, int, os.FileMode) (*os.File, error) ReadFile(string) ([]byte, error) RemoveAll(string) error WriteFile(string, []byte, os.FileMode) error }
Abstracts filesystem operations.
We can't use os.DirFS or fs.StatFS because they lack some methods we need. So we created our own interface.
type RealFS ¶ added in v0.2.0
type RealFS struct{}
This is the non-test implementation of the filesystem interface.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
scope binds variable names to values. It has a stack-like structure that allows inner scopes to inherit values from outer scopes. Variable names are looked up in order of innermost-to-outermost.
For example, a for_each action defines a key value that is assigned to each of a list of values. The new variable introduced in this way "shadows" any variable that may previously exist of the same name. When the for_each loop is finished, then the outer scope's variable becomes available again.
func (*Scope) AllVars ¶ added in v0.7.0
AllVars returns all variable bindings that are in scope. Inner/top-of-stack bindings take priority over outer bindings of the same name.
The returned map is a copy that is owned by the caller; it can be changed safely.
The return value is never nil.
func (*Scope) GoTmplFuncs ¶ added in v0.7.0
GoTmplFuncs returns all the Go-template functions that are in scope. The result is suitable for passing to text/template.Template.Funcs().
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package builtinvar deals with so-called "built in vars".
|
Package builtinvar deals with so-called "built in vars". |
Package errs contains errors that are shared across packages.
|
Package errs contains errors that are shared across packages. |
Package flags contains flags that are commonly used by several commands.
|
Package flags contains flags that are commonly used by several commands. |
Package rules contains function for handling rule evaluation
|
Package rules contains function for handling rule evaluation |
Package spec contains commonly used function for handling spec files
|
Package spec contains commonly used function for handling spec files |
Package render implements the template rendering related subcommands.
|
Package render implements the template rendering related subcommands. |
Package upgrade implements template upgrading: taking a directory containing a rendered template and updating it with the latest version of the template.
|
Package upgrade implements template upgrading: taking a directory containing a rendered template and updating it with the latest version of the template. |