lookpath

package
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: BSD-3-Clause Imports: 6 Imported by: 9

Documentation

Overview

Package lookpath implements utilities to find executables.

Index

Constants

View Source
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

func ExecutableBasename(name string) string

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

func ExecutableFilename(name string) string

ExecutableFilename returns a system specific filename for executable files. On UNIX systems the filename is unchanged.

func Look

func Look(env map[string]string, name string) (string, error)

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

func LookPrefix(env map[string]string, prefix string, names map[string]bool) ([]string, error)

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

func PathFromVars(vars map[string]string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL