Documentation
¶
Index ¶
- Constants
- func CombineEnv(envs ...*[]string) []string
- func CombineEnvMaps(envs ...*map[string]string) map[string]string
- func EnvMapAsSlice(env map[string]string) []string
- func EnvSliceAsMap(env []string) map[string]string
- func GetCacheDir() (string, error)
- func GetOSShell(envShell *platform.PlatformMap[string]) string
- func GetOSShellArgs(cmd string) []string
- func GetRawFileURL(gitURL, ref, path string) (string, error)
- func GetRealPath(env []string, path string) string
- func GetShellWhich() string
- func IsGitURL(url string) bool
- func IsRawFileURL(url string) bool
- func PathExists(path string) (bool, error)
- func ResolveEnvPaths(envs ...[]string) []string
- func RunCmdAsFile(env []string, contents string, envShell *platform.PlatformMap[string]) error
- func RunCmdGetOutput(env []string, bin string, args ...string) ([]byte, error)
- func RunCmdGetSuccess(env []string, bin string, args ...string) (bool, error)
- func RunCmdGetSuccessPassThrough(env []string, bin string, args ...string) (bool, error)
- func RunCmdPassThrough(env []string, bin string, args ...string) error
- func RunCmdPassThroughChained(env []string, commands [][]string) error
- type GitHostType
- type GitURLInfo
Constants ¶
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
CombineEnv merges multiple slices of environment variable strings. Later slices will override earlier ones if keys conflict.
func CombineEnvMaps ¶ added in v1.5.0
CombineEnvMaps merges multiple maps of environment variables. Later maps will override earlier ones if keys conflict.
func EnvMapAsSlice ¶ added in v1.5.0
EnvMapAsSlice converts a map of environment variables to a slice of "KEY=VALUE" strings.
func EnvSliceAsMap ¶ added in v1.5.0
EnvSliceAsMap converts a slice of environment variable strings ("KEY=VALUE") to a map.
func GetCacheDir ¶ added in v1.8.0
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 `$XDG_CACHE_HOME` on Linux/macOS and `%LocalAppData%` 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
GetOSShellArgs returns the appropriate shell arguments for executing a command string.
func GetRawFileURL ¶ added in v1.13.0
GetRawFileURL converts a Git repository URL to a raw file URL for direct access. Supports GitHub, GitLab (including self-hosted), and Bitbucket (including self-hosted). For unknown hosts, it attempts to use GitLab-style raw URLs as a fallback. Parameters:
- gitURL: The Git repository URL (SSH or HTTPS)
- ref: The branch, tag, or commit (defaults to "master" if empty)
- path: The file path within the repository
func GetRealPath ¶
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
IsGitURL checks if a string is likely a Git repository URL (not a raw file URL). It checks for "git@" prefix or URLs ending with ".git".
func IsRawFileURL ¶ added in v1.13.0
IsRawFileURL checks if a URL is a direct raw file URL.
func PathExists ¶ added in v1.4.0
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
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
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 ¶
RunCmdGetOutput executes a command and returns its standard output.
func RunCmdGetSuccess ¶
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
RunCmdGetSuccessPassThrough executes a command, passes through streams, and returns true if it succeeds.
func RunCmdPassThrough ¶
RunCmdPassThrough executes a command and passes through its standard input, output, and error streams. It also resolves environment variable paths.
func RunCmdPassThroughChained ¶
RunCmdPassThroughChained executes a series of commands sequentially, passing through streams. If any command fails, the chain stops and an error is returned.
Types ¶
type GitHostType ¶ added in v1.13.0
type GitHostType string
GitHostType represents the type of Git hosting service.
const ( GitHostGitHub GitHostType = "github" GitHostGitLab GitHostType = "gitlab" GitHostBitbucket GitHostType = "bitbucket" GitHostUnknown GitHostType = "unknown" )
func DetectGitHostType ¶ added in v1.13.0
func DetectGitHostType(host string) GitHostType
DetectGitHostType detects the Git hosting service from a host string. It checks for known patterns in the hostname.
type GitURLInfo ¶ added in v1.13.0
type GitURLInfo struct {
Host string // e.g., "github.com", "gitlab.com"
Owner string // e.g., "chenasraf"
Repo string // e.g., "sofmani"
}
GitURLInfo holds parsed information from a Git URL.
func ParseGitURL ¶ added in v1.13.0
func ParseGitURL(url string) (*GitURLInfo, error)
ParseGitURL parses a Git URL (SSH or HTTPS) and extracts host, owner, and repo. Supports formats:
- git@github.com:owner/repo.git
- https://github.com/owner/repo.git
- https://github.com/owner/repo