Documentation ¶
Index ¶
- Constants
- func Copy(ctx context.Context, destination, source string) error
- func CopyAll(destination, source string, opts ...CopyAllOption) error
- func FindAllFiles(ctx context.Context, startPath, matchGlob string) (output []string, err error)
- func FindFiles(ctx context.Context, targetPath string, matchGlob string) (output []string, err error)
- func MatchInject(corpus []byte, expr, inject string) []byte
- func MatchRemove(corpus []byte, expr string) []byte
- func RemoveFile(ctx context.Context, path string) error
- func RemoveQuotes(value string) string
- type CopyAllOption
- type CopyAllOptions
- type CopyAllSymlinkMode
- type CopyRewriter
- func (cr CopyRewriter) DebugOrDefault() bool
- func (cr CopyRewriter) Debugf(format string, args ...interface{})
- func (cr CopyRewriter) Execute(ctx context.Context) error
- func (cr CopyRewriter) GetStderr() io.Writer
- func (cr CopyRewriter) GetStdout() io.Writer
- func (cr CopyRewriter) QuietOrDefault() bool
- func (cr CopyRewriter) VerboseOrDefault() bool
- func (cr CopyRewriter) Verbosef(format string, args ...interface{})
- type FileInfo
- type GoAstFilter
- type GoAstNodeVisitor
- type GoAstRewriteOption
- type GoAstRewriteOptions
- type GoAstVisitor
- type GoImportRewriteOption
- func OptGoImportAddName(name string) GoImportRewriteOption
- func OptGoImportNameMatches(expr string) GoImportRewriteOption
- func OptGoImportPathMatches(expr string) GoImportRewriteOption
- func OptGoImportPathRewrite(matchExpr, outputExpr string) GoImportRewriteOption
- func OptGoImportSetAlias(name string) GoImportRewriteOption
- func OptGoImportSetPath(path string) GoImportRewriteOption
- type GoImportRewriteOptions
- type GoImportVisitor
- type StringSubstitution
- type TempDir
Constants ¶
const ( DefaultFilePerms = 0644 DefaultDirPerms = 0755 )
Defaults
Variables ¶
This section is empty.
Functions ¶
func CopyAll ¶
func CopyAll(destination, source string, opts ...CopyAllOption) error
CopyAll copies all files and directories from a source path to a destination path recurrsively.
func FindAllFiles ¶
FindAllFiles finds all the files that match a given glob recursively.
func FindFiles ¶
func FindFiles(ctx context.Context, targetPath string, matchGlob string) (output []string, err error)
FindFiles finds all files in a given path that matches a given glob but does not traverse recursively.
func MatchInject ¶
MatchInject injects a given value after the any instances of a given expression.
func MatchRemove ¶
MatchRemove removes a line if it matches a given expression.
func RemoveFile ¶
RemoveFile removes a file and prints a debug message if the context sets that flag.
func RemoveQuotes ¶
RemoveQuotes removes quotes from a string
Types ¶
type CopyAllOption ¶
type CopyAllOption func(*CopyAllOptions)
CopyAllOption is a mutator for copy all options
func OptCopyAllSkipGlobs ¶
func OptCopyAllSkipGlobs(globs ...string) CopyAllOption
OptCopyAllSkipGlobs sets the skip provider to a glob matcher based on a given set of glob(s).
func OptCopyAllSymlinkMode ¶
func OptCopyAllSymlinkMode(mode CopyAllSymlinkMode) CopyAllOption
OptCopyAllSymlinkMode sets the symlink mode.
type CopyAllOptions ¶
type CopyAllOptions struct { SymlinkMode CopyAllSymlinkMode SkipProvider func(os.FileInfo) bool }
CopyAllOptions are the options for copy all.
type CopyAllSymlinkMode ¶
type CopyAllSymlinkMode int
CopyAllSymlinkMode is how symlinks should be handled
var ( // CopyAllSymlinkModeShallow will copy links from the source to the destination as links. CopyAllSymlinkModeShallow CopyAllSymlinkMode = 0 // CopyAllSymlinkModeDeep will traverse into the link destination and copy any files recursively. CopyAllSymlinkModeDeep CopyAllSymlinkMode = 1 // CopyAllSymlinkModeSkip will skip any links discovered. CopyAllSymlinkModeSkip CopyAllSymlinkMode = 2 )
CopyAllSymlinkMode(s)
type CopyRewriter ¶
type CopyRewriter struct { Source string Destination string SkipGlobs []string GoImportVisitors []GoImportVisitor GoAstVistiors []GoAstVisitor StringSubstitutions []StringSubstitution DryRun bool RemoveDestination bool KeepTemporary bool Quiet *bool Verbose *bool Debug *bool Stdout io.Writer Stderr io.Writer }
CopyRewriter copies a source to a destination, and applies rewrite rules to the file(s) it copies.
func (CopyRewriter) DebugOrDefault ¶
func (cr CopyRewriter) DebugOrDefault() bool
DebugOrDefault returns a value or a default.
func (CopyRewriter) Debugf ¶
func (cr CopyRewriter) Debugf(format string, args ...interface{})
Debugf writes to stdout if the `Debug` flag is true.
func (CopyRewriter) Execute ¶
func (cr CopyRewriter) Execute(ctx context.Context) error
Execute is the command body.
func (CopyRewriter) GetStderr ¶
func (cr CopyRewriter) GetStderr() io.Writer
GetStderr returns standard error.
func (CopyRewriter) GetStdout ¶
func (cr CopyRewriter) GetStdout() io.Writer
GetStdout returns standard out.
func (CopyRewriter) QuietOrDefault ¶
func (cr CopyRewriter) QuietOrDefault() bool
QuietOrDefault returns a value or a default.
func (CopyRewriter) VerboseOrDefault ¶
func (cr CopyRewriter) VerboseOrDefault() bool
VerboseOrDefault returns a value or a default.
func (CopyRewriter) Verbosef ¶
func (cr CopyRewriter) Verbosef(format string, args ...interface{})
Verbosef writes to stdout if the `Verbose` flag is true.
type GoAstFilter ¶
GoAstFilter is a delegate type that filters ast nodes for visiting.
type GoAstNodeVisitor ¶
GoAstNodeVisitor mutates a given node.
type GoAstRewriteOption ¶
type GoAstRewriteOption func(*GoAstRewriteOptions)
GoAstRewriteOption the ast rewrite options.
func GoIsCall ¶
func GoIsCall(fn string) GoAstRewriteOption
GoIsCall returns a filter that determines if a function is a given name.
It will only evaluate for function calls that appear local to the current package, that is, function calls that do not have a selector.
func GoIsPackageCall ¶
func GoIsPackageCall(pkg, fn string) GoAstRewriteOption
GoIsPackageCall returns a filter that determines if a function is a given sel.Fn.
It will only evaluate for function calls that use a package selector that is, function calls that have a selector.
func GoRewriteCall ¶
func GoRewriteCall(fn string) GoAstRewriteOption
GoRewriteCall changes a given function as filtered by a filter to a given call noted by Fn.
func GoRewritePackageCall ¶
func GoRewritePackageCall(sel, fn string) GoAstRewriteOption
GoRewritePackageCall changes a given function as filtered by a filter to a given call noted by sel.Fn.
type GoAstRewriteOptions ¶
type GoAstRewriteOptions struct { Filter GoAstFilter NodeVisitor GoAstNodeVisitor }
GoAstRewriteOptions breaks the mutator out into field specific mutators.
type GoAstVisitor ¶
GoAstVisitor mutates an ast node.
func GoAstRewrite ¶
func GoAstRewrite(opts ...GoAstRewriteOption) GoAstVisitor
GoAstRewrite returns a go ast visitor with a given set of options.
type GoImportRewriteOption ¶
type GoImportRewriteOption func(*GoImportRewriteOptions)
GoImportRewriteOption mutates the import rewrite options
func OptGoImportAddName ¶
func OptGoImportAddName(name string) GoImportRewriteOption
OptGoImportAddName adds a name if one is not already specified.
func OptGoImportNameMatches ¶
func OptGoImportNameMatches(expr string) GoImportRewriteOption
OptGoImportNameMatches returns a rewrite filter that returns if an import name matches a given expression.
func OptGoImportPathMatches ¶
func OptGoImportPathMatches(expr string) GoImportRewriteOption
OptGoImportPathMatches returns a rewrite filter that returns if an import path matches a given expression.
func OptGoImportPathRewrite ¶
func OptGoImportPathRewrite(matchExpr, outputExpr string) GoImportRewriteOption
OptGoImportPathRewrite returns a path filter and rewrite expression.
func OptGoImportSetAlias ¶
func OptGoImportSetAlias(name string) GoImportRewriteOption
OptGoImportSetAlias sets the import alias to a given value.
Setting to "" will remove the alias.
func OptGoImportSetPath ¶
func OptGoImportSetPath(path string) GoImportRewriteOption
OptGoImportSetPath sets an import path to a given value.
type GoImportRewriteOptions ¶
type GoImportRewriteOptions struct { Filter func(context.Context, *ast.ImportSpec) (bool, error) CommentVisitor func(context.Context, *ast.CommentGroup) error DocVisitor func(context.Context, *ast.CommentGroup) error NameVisitor func(context.Context, *ast.Ident) error PathVisitor func(context.Context, *ast.BasicLit) error }
GoImportRewriteOptions breaks the mutator out into field specific mutators.
func (GoImportRewriteOptions) Apply ¶
func (opts GoImportRewriteOptions) Apply(ctx context.Context, importSpec *ast.ImportSpec) error
Apply applies the options to the import.
type GoImportVisitor ¶
type GoImportVisitor func(context.Context, *ast.ImportSpec) error
GoImportVisitor mutates an ast import.
func GoImportRewrite ¶
func GoImportRewrite(opts ...GoImportRewriteOption) GoImportVisitor
GoImportRewrite visits and optionally mutates imports for go files.
func GoImportRewritePrefix ¶
func GoImportRewritePrefix(sourcePrefix, destinationPrefix string) GoImportVisitor
GoImportRewritePrefix is a helper that returns a visitor that takes a source path and rewrites it as the destination path preserving any path segments after the source if it matches the sourcePrefix.
func ParseGoImportRewriteRules ¶
func ParseGoImportRewriteRules(rewriteRules []string) (output []GoImportVisitor)
ParseGoImportRewriteRules parses go import rewrite rules as strings.
type StringSubstitution ¶
StringSubstitution is a mutator for a string. It returns the modified string, and a bool if the rule matched or not.
func SubstituteString ¶
func SubstituteString(before, after string) StringSubstitution
SubstituteString rewrites a string literal.
type TempDir ¶
type TempDir struct {
Path string
}
TempDir is a directory that can be cleaned up with Close.
func CreateTempDir ¶
CreateTempDir creates a temporary directory with a given prefix.