Documentation ¶
Overview ¶
Package lookpath implements utilities to find executables.
Index ¶
- Constants
- func ExecutableBasename(name string) string
- func ExecutableFilename(name string) string
- func Look(env map[string]string, name string) (string, error)
- func LookPrefix(env map[string]string, prefix string, names map[string]bool) ([]string, error)
- func PathFromVars(vars map[string]string) string
Constants ¶
const PathEnvVar = "PATH"
PathEnvVar is the system specific environment variable name for command paths; commonly PATH on UNIX systems. Deprecated: use PathFromVars instead.
Variables ¶
This section is empty.
Functions ¶
func ExecutableBasename ¶ added in v0.1.9
ExecutableBasename returns the system specific basename (i.e. without any executable suffix) for executable files. On UNIX systems the filename is unchanged.
func ExecutableFilename ¶ added in v0.1.9
ExecutableFilename returns a system specific filename for executable files. On UNIX systems the filename is unchanged.
func Look ¶
Look returns the absolute path of the executable with the given name. If name only contains a single path component, the dirs in env["PATH"] or env["Path"] on windows (use lookpath.PathEnvVar to obtain the os specific value) are consulted, and the first match is returned. Otherwise, for multi-component paths, the absolute path of the name is looked up directly.
The behavior is the same as LookPath in the os/exec package, but allows the env to be passed in explicitly. On Windows systems PATH is copied to Path in env unless Path is already defined. Again, on Windows, the returned executable name does not include the .exe suffix.
func LookPrefix ¶
LookPrefix returns the absolute paths of all executables with the given name prefix. If prefix only contains a single path component, the directories in env["PATH"] are consulted. Otherwise, for multi-component prefixes, only the directory containing the prefix is consulted. If multiple executables with the same base name match the prefix in different directories, the first match is returned. Returns a list of paths sorted by base name.
The names are filled in as the method runs, to ensure the first matching property. As a consequence, you may pass in a pre-populated names map to prevent matching those names. It is fine to pass in a nil names map.
func PathFromVars ¶ added in v0.1.12
PathFromVars returns the system specific path from the given environment. It is preferable to use this function rather than directly accessing the environment variables using PathEnvVar since on some systems, such as Windows, PATH or Path maybe used apparently arbitrarily.
Types ¶
This section is empty.