Documentation
¶
Index ¶
- Constants
- func CopyDirectory(src, dst string, overwrite CopyOverwriteType) (err error)
- func CopyFiles(dst string, overwrite CopyOverwriteType, src ...string) (err error)
- func ExecuteShellCommand(command string) (result []byte, err error)
- func GetModulePath(path string, modules map[string]string) (newPath string, err error)
- func ModuleExpandFileList(args []string, modules map[string]string) (list []string)
- func ModulePaths() (ret map[string]string, err error)
- func SplitList(s string) (list []string)
- type CopyOverwriteType
Constants ¶
const ( CopyDoNotOverwrite CopyOverwriteType = 0 CopyOverwrite = 1 CopyOverwriteOnlyIfNewer = 2 )
Variables ¶
This section is empty.
Functions ¶
func CopyDirectory ¶
func CopyDirectory(src, dst string, overwrite CopyOverwriteType) (err error)
CopyDirectory copies the src directory to the destination directory. The destination directory will be the parent of the resulting directory, and the result will have the same name as the source. If the destination already exists, it will perform a kind of merge, where existing files will not be touched, and only new files will be copied. If you want to replace the destination, delete it first. dst must exist.
func CopyFiles ¶
func CopyFiles(dst string, overwrite CopyOverwriteType, src ...string) (err error)
CopyFiles copies the src files or directories to the destination
If there is more than one source, the destination must be a directory that exists. The items listed will be copied inside the destination directory.
If there is only one source, the destination must be:
- A directory that exists, in which case the source will be placed in the destination directory
- A file that exists, in which case the source will overwrite the destination. The source must also be a single file.
- A file that does not exist, but whose parent directory does exist, in which case the file will be copied and renamed to the destination.
If overwrite is true, files that already exist will be overwritten. If overwrite is false, only new files will be created. If a directory is over-writing another directory, this will determine what happens when file names are duplicates. Note that old files in a directory will not be deleted when a directory overwrites another directory. If you want old files to be deleted, empty the destination directory first.
func ExecuteShellCommand ¶
ExecuteShellCommand executes a shell command in the current working directory and returns its output, if any. The result is stdOut. If you get an error, you can cast err to (*exec.ExitError) and read the stdErr member to see the error message that was generated. The command string is the shell command, complete with all arguments.
func GetModulePath ¶
GetModulePath compares the given path with the list of modules and if the path begins with a module name, it will substitute the absolute path for the module name. It will clean the path given as well. modules is the output from ModulePaths. Module paths always use forward slashes. The resulting path uses the native path separator.
func ModuleExpandFileList ¶
Given a list of arguments that represent command line arguments that would be a list of files, directories, or glob patterns, this will do the following:
replace any environment variables with their values replace any items that start with a module with the actual location on disk expand any glob patterns remove duplicates
It will return the final list. modules is the list of modules returned from ModulePaths. Glob patterns will be matched, and if nothing is found, no file will be generated. However, if a path does not have a glob pattern, but does not exist, it will be left in the list, since it might refer to a file or directory you want to add. The list out is not necessarily in the same order as the list in.
func ModulePaths ¶
ModulePaths returns a listing of the paths of all the modules included in the build, keyed by module name, as if the build was run from the current working directory. Note that Go's module support can change a build based on the go.mod file found, which is dependent on the current working directory.
If we are building without module support, it will return only the top paths to packages, since everything in this situation will be relative to GOPATH.
func SplitList ¶
SplitList will split a file and/or directory list into individual items in a cross-platform way. In other words, the list can be specified in a Unix(colons) or Windows(semicolon) friendly way, and it will split the list regardless of the platform the list was designed for, or run on. This means on Unix, you can't use a semicolon in a file name, and on windows, you can't use a colon, but that should not be an issue for most people.
Types ¶
type CopyOverwriteType ¶
type CopyOverwriteType int
CopyOverwriteType is used by the CopyFiles function to determine how to treat file collisions when copying over a file that already exists.