Documentation
¶
Index ¶
- func ExpandEnvRefs(s string) string
- func ExpandHomeDir(path string) (string, error)
- func ExpandPath(p string) string
- func ExpandWorkingDir(field, p string) string
- func IsWithin(p, dir string) bool
- func NormalizeEnvRefs(s string) string
- func RelativeTo(p, baseDir string) string
- func ShortenHome(p string) string
- func ShortenHomeDir(p, homeDir string) string
- func ValidatePathInDirectory(path, allowedDir string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandEnvRefs ¶ added in v1.97.0
ExpandEnvRefs resolves only the plain `${env.VAR}` form (see jsEnvRef) against the OS environment, leaving every other `$`-shaped substring (including `$VAR` and `${VAR}`) untouched. Use it for fields whose values may legitimately contain literal `$` (e.g. env values forwarded to subprocesses), where a full os.Expand pass would mangle them (issue #2615). Unset variables expand to the empty string, matching the JS-template semantics; a debug log makes that observable since the resulting value is otherwise indistinguishable from a legitimate "".
func ExpandHomeDir ¶ added in v1.58.0
ExpandHomeDir expands a leading home-directory reference in a path. It expands "~", "~/...", and "~\\..." on Windows. Other tilde forms, such as "~user/...", are returned unchanged.
func ExpandPath ¶ added in v1.44.0
ExpandPath expands shell-like patterns in a file path:
- ~ or ~/ at the start is replaced with the user's home directory
- Environment variables like ${HOME} or $HOME are expanded
- The JS-template form ${env.HOME} is accepted as an alias for ${HOME}
func ExpandWorkingDir ¶ added in v1.97.0
ExpandWorkingDir expands a working-directory field like ExpandPath, and warns when a non-empty value expands to empty (typically an unset variable, e.g. `working_dir: ${env.UNSET}`). Callers fall back to a default directory in that case, which would otherwise be a silent surprise for commands that mutate files (#2615).
func NormalizeEnvRefs ¶ added in v1.89.0
NormalizeEnvRefs rewrites the JS-template form `${env.VAR}` to the shell form `${VAR}`, so os.Expand-based callers also accept the JS-style syntax used elsewhere in the config (issue #2615). Richer JS expressions are left untouched; see jsEnvRef.
func RelativeTo ¶ added in v1.66.0
RelativeTo returns p relative to baseDir when both paths are absolute and filepath.Rel can compute a relative path. Otherwise it returns p cleaned.
func ShortenHome ¶ added in v1.66.0
ShortenHome replaces the current user's home directory prefix with "~".
func ShortenHomeDir ¶ added in v1.66.0
ShortenHomeDir replaces a leading homeDir prefix with "~".
func ValidatePathInDirectory ¶
Types ¶
This section is empty.