Documentation ¶
Index ¶
- Constants
- Variables
- func CelCompileAndEval(ctx context.Context, scope *Scope, expr model.String, outPtr any) error
- func Copy(ctx context.Context, fs FS, src, dst string) error
- func CopyFile(ctx context.Context, pos *model.ConfigPos, rfs FS, src, dst string, ...) (outErr error)
- func CopyRecursive(ctx context.Context, pos *model.ConfigPos, p *CopyParams) (outErr error)
- func Exists(path string) (bool, error)
- func ExistsFS(fs FS, path string) (bool, error)
- func HasDotDot(path string) bool
- func IsNotExistErr(err error) bool
- func IsReservedInDest(relPath string) bool
- func IsReservedStdout(relPath string) bool
- func JoinIfRelative(cwd, path string) string
- 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 ExitCodeError
- 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) Remove(name string) error
- func (r *RealFS) RemoveAll(name string) error
- func (r *RealFS) Rename(from, to 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
- type SymlinkForbiddenError
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.
Variables ¶
var DoNotModifyHeader = []byte("# Generated by the \"abc\" 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 Copy ¶ added in v0.8.0
Copy copies the file src to dst. It's a wrapper around CopyFile that hides unneeded arguments.
func CopyFile ¶ added in v0.8.0
func CopyFile(ctx context.Context, pos *model.ConfigPos, rfs FS, src, dst string, dryRun bool, tee io.Writer) (outErr error)
CopyFile copies the contents of src to dst.
tee is nil-able. If not nil, it will be written to with the file contents.
func CopyRecursive ¶ added in v0.2.0
CopyRecursive recursively copies a directory to another directory.
If the source directory contains a symlink, then SymlinkForbiddenError will be returned.
func Exists ¶ added in v0.8.0
Exists returns whether the given path is a file or directory that exists. We wrote this wrapper because it's a little complex and irritating to deal with the way that os.Stat() considers nonexistence to be an error.
func ExistsFS ¶ added in v0.8.0
Exists is like Exists, but takes a FS as a parameter for error injection.
func HasDotDot ¶ added in v0.9.2
HasDotDot returns whether the input path contains any ".." parent directory references, so they can be rejected in certain cases.
func IsNotExistErr ¶ added in v0.8.0
IsNotExistErr 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 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 JoinIfRelative ¶ added in v0.7.0
JoinIfRelative returns path if it's an absolute path, otherwise filepath.Join(cwd, path).
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 // AllowPreexisting prevents CopyRecursive from returning error when copying // over an existing file. The default is to conservatively fail. // // This has no effect on directories, only files. AllowPreexisting 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) // DryRun skips actually copying 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. 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 ExitCodeError ¶ added in v0.8.0
An implementation of error that contains an command exit status. This is intended to be returned from a Run() function when a command wants to return a specific error code to the OS.
func (*ExitCodeError) Error ¶ added in v0.8.0
func (e *ExitCodeError) Error() string
func (*ExitCodeError) Unwrap ¶ added in v0.8.0
func (e *ExitCodeError) Unwrap() error
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) Rename(string, string) error Remove(string) 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().
type SymlinkForbiddenError ¶ added in v0.9.2
type SymlinkForbiddenError struct { // The relative path where the symlink was found. Relative to SrcRoot. Path string }
SymlinkForbiddenError is the error returned from CopyRecursive when a symlink is encountered in the source directory.
func (*SymlinkForbiddenError) Error ¶ added in v0.9.2
func (e *SymlinkForbiddenError) Error() string
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. |