utils

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: CC0-1.0 Imports: 14 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 `$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

func GetOSShellArgs(cmd string) []string

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

func GetRawFileURL added in v1.13.0

func GetRawFileURL(gitURL, ref, path string) (string, error)

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

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 repository URL (not a raw file URL). It checks for "git@" prefix or URLs ending with ".git".

func IsRawFileURL added in v1.13.0

func IsRawFileURL(url string) bool

IsRawFileURL checks if a URL is a direct raw file URL.

func ParsePrettyDuration added in v1.26.0

func ParsePrettyDuration(s string) (time.Duration, error)

ParsePrettyDuration parses a human-friendly duration string like "1d", "2w", "3m", "60s", "1h". Supported units: s (seconds), m (minutes), h (hours), d (days), w (weeks). Multiple components can be combined, e.g. "1d12h".

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

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:

Jump to

Keyboard shortcuts

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