utils

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: CC0-1.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const UNIX_DEFAULT_SHELL string = "bash"

UNIX_DEFAULT_SHELL is the default shell used on Unix-like systems if SHELL environment variable is not set.

Variables

This section is empty.

Functions

func CombineEnv added in v1.5.0

func CombineEnv(envs ...*[]string) []string

CombineEnv merges multiple slices of environment variable strings. Later slices will override earlier ones if keys conflict.

func CombineEnvMaps added in v1.5.0

func CombineEnvMaps(envs ...*map[string]string) map[string]string

CombineEnvMaps merges multiple maps of environment variables. Later maps will override earlier ones if keys conflict.

func EnvMapAsSlice added in v1.5.0

func EnvMapAsSlice(env map[string]string) []string

EnvMapAsSlice converts a map of environment variables to a slice of "KEY=VALUE" strings.

func EnvSliceAsMap added in v1.5.0

func EnvSliceAsMap(env []string) map[string]string

EnvSliceAsMap converts a slice of environment variable strings ("KEY=VALUE") to a map.

func GetCacheDir added in v1.8.0

func GetCacheDir() (string, error)

GetCacheDir returns the path to the user's cache directory for the application. It creates the directory if it doesn't exist. The cache directory is typically located at `~/.config/.cache` on Linux/macOS and `%APPDATA%\.cache` on Windows.

func GetOSShell added in v1.1.0

func GetOSShell(envShell *platform.PlatformMap[string]) string

GetOSShell returns the appropriate shell for the current operating system. It considers the SHELL environment variable on Unix-like systems and allows overrides via envShell.

func GetOSShellArgs added in v1.1.0

func GetOSShellArgs(cmd string) []string

GetOSShellArgs returns the appropriate shell arguments for executing a command string.

func GetRealPath

func GetRealPath(env []string, path string) string

GetRealPath resolves a path string, expanding environment variables and replacing "~" with the user's home directory. It takes a slice of environment variables to temporarily set during expansion.

func GetShellWhich added in v1.1.0

func GetShellWhich() string

GetShellWhich returns the command used to find the path of an executable (e.g., "which" or "where").

func IsGitURL added in v1.4.0

func IsGitURL(url string) bool

IsGitURL checks if a string is likely a Git URL. It checks for "https://" or "git@" prefixes.

func PathExists added in v1.4.0

func PathExists(path string) (bool, error)

PathExists checks if a file or directory exists at the given path. It returns true if the path exists, false otherwise. It does not distinguish between files and directories. An error is returned if os.Stat encounters an issue other than fs.ErrNotExist.

func ResolveEnvPaths added in v1.5.0

func ResolveEnvPaths(envs ...[]string) []string

ResolveEnvPaths takes one or more slices of environment variable strings (e.g., "KEY=VALUE"), resolves any paths within the values using GetRealPath, and returns a single combined slice.

func RunCmdAsFile added in v1.2.0

func RunCmdAsFile(env []string, contents string, envShell *platform.PlatformMap[string]) error

RunCmdAsFile writes the given contents to a temporary shell script and executes it. This is useful for running multi-line commands or scripts.

func RunCmdGetOutput

func RunCmdGetOutput(env []string, bin string, args ...string) ([]byte, error)

RunCmdGetOutput executes a command and returns its standard output.

func RunCmdGetSuccess

func RunCmdGetSuccess(env []string, bin string, args ...string) (bool, error)

RunCmdGetSuccess executes a command and returns true if it succeeds (exit code 0). Standard input, output, and error are not passed through.

func RunCmdGetSuccessPassThrough added in v1.9.4

func RunCmdGetSuccessPassThrough(env []string, bin string, args ...string) (bool, error)

RunCmdGetSuccessPassThrough executes a command, passes through streams, and returns true if it succeeds.

func RunCmdPassThrough

func RunCmdPassThrough(env []string, bin string, args ...string) error

RunCmdPassThrough executes a command and passes through its standard input, output, and error streams. It also resolves environment variable paths.

func RunCmdPassThroughChained

func RunCmdPassThroughChained(env []string, commands [][]string) error

RunCmdPassThroughChained executes a series of commands sequentially, passing through streams. If any command fails, the chain stops and an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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