utils

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileTypeJSON   = "json"
	FileTypeYAML   = "yaml"
	FileTypeBinary = "binary"
)
View Source
const (
	CacheDir     = ".local/state/keg"
	OutdatedFile = "keg_brew_update.json"
	CacheExpiry  = 24 * time.Hour
)

Variables

View Source
var LookForFileInPath = DefaultLookForFileInPath

Functions

func AssetName

func AssetName(version string) string

func BoolToInt

func BoolToInt(b bool) int

func ChecksumVerifiedReader

func ChecksumVerifiedReader(r io.Reader, expected string) (io.Reader, error)

ChecksumVerifiedReader returns a new reader if SHA256 checksum matches.

func CommandExists

func CommandExists(command string) bool

commandExists Verify if a command exists in the system

func ConfirmOrAbort

func ConfirmOrAbort(message, errormsg string) error

func CreateFile

func CreateFile(path string, content any, fileType string, perm os.FileMode) error

func CreateStatusTable

func CreateStatusTable(title string, packages []PackageStatus)

func DefaultLookForFileInPath added in v0.2.0

func DefaultLookForFileInPath(file string) (string, error)

func DefaultUpdateState

func DefaultUpdateState() map[string]interface{}

func DeferRestore

func DeferRestore(key, val string)

func EnsureUpdateStateFileExists

func EnsureUpdateStateFileExists() (string, error)

func FileExists

func FileExists(path string) (bool, error)

func FileReader

func FileReader(path string, fileType string, out interface{}) error

func Filter

func Filter[T any](in []T, keep func(T) bool) []T

func Flat

func Flat[T any](slices [][]T) []T

func GenerateRandomString

func GenerateRandomString(length int) string

func GetHomeDir

func GetHomeDir() string

func GetMaxWidth

func GetMaxWidth(lines []string) int

func GzipBytes added in v0.2.0

func GzipBytes(src []byte) ([]byte, error)

func HumanSize added in v0.2.0

func HumanSize(bytes int64) string

func Includes

func Includes[T comparable](in []T, target T) bool

func InstalledSet added in v0.2.1

func InstalledSet(r runner.CommandRunner) (map[string]bool, error)

InstalledSet returns a fast membership map of installed brew formulae. Key: package name, Value: true if installed.

func IsHomebrewInstalled

func IsHomebrewInstalled() bool

IsHomebrewInstalled Verify if Homebrew is already installed

func IsNewerVersion

func IsNewerVersion(remote, local string) (bool, error)

IsNewerVersion compares two semantic versions and returns true if remote > local.

func IsSemver

func IsSemver(v string) bool

IsSemver returns true if the string is a valid semver (x.y.z).

func Keys

func Keys[K comparable, V any](m map[K]V) []K

func LessByTypeThenKey added in v0.1.6

func LessByTypeThenKey(typeA, typeB, keyA, keyB string) bool

LessByTypeThenKey applies (type rank) then (alpha by key, case-insensitive).

func ListInstalled added in v0.2.1

func ListInstalled(r runner.CommandRunner) ([]string, error)

ListInstalled returns the installed brew formulae as a slice (if you ever need it).

func MakeFilePath

func MakeFilePath(dir string, filename string) string

func Map

func Map[T any, R any](in []T, f func(T) R) []R

func MaybeGunzip added in v0.2.0

func MaybeGunzip(src io.ReadCloser) (io.ReadCloser, error)

maybeGunzip returns a reader that yields the decompressed stream if 'src' is gzip, else returns src as-is. It preserves the ability to Close().

func MustSet

func MustSet(key, val string) (old string)

func NewBytesReadSeekCloser added in v0.2.0

func NewBytesReadSeekCloser(b []byte) io.ReadSeekCloser

func NewUpdateState

func NewUpdateState(base config.UpdateState, isNewer bool, version string) config.UpdateState

func PackageManager added in v0.1.3

func PackageManager() (pmCmd, error)

func ParseChecksumsForBinary

func ParseChecksumsForBinary(body, tag string) (string, error)

func ParseSecureURL

func ParseSecureURL(raw string) (*url.URL, error)

func RunBrewCommand

func RunBrewCommand(r runner.CommandRunner, action, pkg string, ignoreWarnings []string) error

RunBrewCommand executes a brew command and handles warnings

func SetHomebrewPath

func SetHomebrewPath() error

func Some

func Some[T any](in []T, pred func(T) bool) bool

func SortByTypeAndKey added in v0.1.6

func SortByTypeAndKey[T any](xs []T, typeOf func(T) string, keyOf func(T) string)

SortByTypeAndKey sorts any slice using extractor funcs.

func StripANSI

func StripANSI(input string) string

func TransformToMap

func TransformToMap[T any](lines []string, transform func(string) (string, T)) map[string]T

func TypeRank added in v0.1.6

func TypeRank(t string) int

TypeRank returns a priority rank: lower is higher priority.

func ValidateBinaryArgs

func ValidateBinaryArgs(args []string, binary string) error

func ValidateSHA256Checksum

func ValidateSHA256Checksum(filePath, expectedChecksum string) (err error)

ValidateSHA256Checksum verifies if the SHA256 hash of the file matches the expected checksum.

func ValidateVersion

func ValidateVersion(info *VersionInfo) error

func WarnBrewInstallation

func WarnBrewInstallation(path string)

func WriteFileAtomic added in v0.2.0

func WriteFileAtomic(tmpPath, finalPath string, r io.Reader) error

func WriteJSONAtomic added in v0.2.0

func WriteJSONAtomic(path string, v any) error

Types

type PackageStatus

type PackageStatus struct {
	Name      string
	Installed string
	Status    string
}

type VersionInfo

type VersionInfo struct {
	Version string `json:"version"`
	URL     string `json:"url"`
	SHA256  string `json:"sha256"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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