util

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoShellOnWindows = errors.New("shell{} is not supported on Windows. please use command{}")

ErrNoShellOnWindows occurs when GetShell() is run on a Windows machine.

View Source
var ErrUnknownShell = errors.New("unable to determine shell from environment. please set the $SHELL environment variable")

ErrUnknownShell occurs when the $SHELL environment variable is empty or not set.

Functions

func EnsureDirectory added in v0.3.1

func EnsureDirectory(dir string) error

EnsureDirectory will ensure that the full path to the destination directory exists. If the full path exists, this is a no-op and will return nil. Otherwise, it will create any directories that do not exist in the destination path. Any directories created will be given file permissions 0755.

func FindInInterface

func FindInInterface(iface interface{}, mapKeys ...string) (interface{}, error)

FindInInterface treats an interface{} like a (nested) map, and searches through its contents for a given list of mapKeys. For example, given an interface{} containing a map like iface ~ interface{}{"top": {"mid": {"bottom": "desired_value"}}} one could fetch an interface{} of "desired_value" with FindInInterface(iface, "top", "mid", "bottom") then afterwards cast it to a string, or whatever type you're expecting.

func GetShell

func GetShell() (string, error)

GetShell returns the value of the $SHELL environment variable, or an error if on Windows or the variable is not set.

func HostCommandExists added in v0.5.0

func HostCommandExists(cmd string) (bool, error)

HostCommandExists takes a single OS-level command name, returning true if it exists in $PATH; false/CommandNotFoundError otherwise

func InterfaceToJSON

func InterfaceToJSON(mapVar interface{}) ([]byte, error)

InterfaceToJSON converts an interface{} to JSON.

func IsInRange

func IsInRange(target, since, until time.Time) bool

func JSONToFile

func JSONToFile(JSON []byte, outFile string) error

JSONToFile accepts JSON and an output file path to create a JSON file.

func SplitFilepath

func SplitFilepath(path string) (dir string, file string)

SplitFilepath takes a full path string and turns it into directory and file parts. In particular, it's useful for passing into runner.NewCopy()

func TarGz

func TarGz(sourceDir string, destFileName string, baseName string) error

TarGz is a utility function for archiving and compressing files. Its arguments include the source directory that you wish to archive; a destination filename, which is the .tar.gz file you want to create; and a baseName, which is the name of the directory that should be created when the resulting .tar.gz file is later extracted.

func WriteJSON

func WriteJSON(iface interface{}, filePath string) error

WriteJSON converts an interface{} to JSON then writes to filePath.

Types

type CommandNotFoundError added in v0.5.0

type CommandNotFoundError struct {
	// contains filtered or unexported fields
}

func (CommandNotFoundError) Error added in v0.5.0

func (e CommandNotFoundError) Error() string

func (CommandNotFoundError) Unwrap added in v0.5.0

func (e CommandNotFoundError) Unwrap() error

Jump to

Keyboard shortcuts

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