util

package
v0.5.15 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BRIGHT_GREEN = color.New(color.FgHiGreen, color.Bold)
View Source
var Logger = log.New(os.Stdout, "[boilerplate] ", log.LstdFlags)

A simple logger we can use to get consistent log formatting through out the app

Functions

func ClearTerminal added in v0.5.8

func ClearTerminal()

Clear the terminal screen in a cross-platform compatible manner

func CommandInstalled

func CommandInstalled(command string) bool

Return true if the OS has the given command installed

func CopyFile

func CopyFile(source string, destination string) error

Copy a file from source to destination

func CopyFolder added in v0.3.0

func CopyFolder(srcFolder string, targetFolder string) error

Copy all the files and folders in srcFolder to targetFolder.

func IsDir

func IsDir(path string) bool

Return true if the path points to a directory

func IsTextFile

func IsTextFile(path string) (bool, error)

IsTextFile - usage of mimetype library to identify if the file is binary or text.

func ListContains added in v0.0.6

func ListContains(needle string, haystack []string) bool

Return true if the given list of strings (haystack) contains the given string (needle)

func MarshalListOfObjectsToYAML added in v0.3.6

func MarshalListOfObjectsToYAML(inputList []interface{}) ([]interface{}, error)

MarshalListOfObjectsToYAML will marshal the list of objects to yaml by calling MarshalYAML on every item in the list and return the results as a list. This is useful when building a custom YAML marshaler.

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

Merge all the maps into one. Sadly, Go has no generics, so this is only defined for string to interface maps.

func PathExists

func PathExists(path string) bool

Return true if the path exists

func PromptUserForInput

func PromptUserForInput(prompt string) (string, error)

Prompt the user for text in the CLI. Returns the text entered by the user.

func PromptUserForYesNo

func PromptUserForYesNo(prompt string) (bool, error)

Prompt the user for a yes/no response and return true if they entered yes.

func RunCommandAndGetOutput

func RunCommandAndGetOutput(command string, args ...string) (string, error)

Run the given command return its stdout and stderr as a string

func RunShellCommand added in v0.3.0

func RunShellCommand(workingDir string, envVars []string, command string, args ...string) error

Run the given shell command with the given environment variables and arguments in the given working directory

func RunShellCommandAndGetOutput added in v0.3.0

func RunShellCommandAndGetOutput(workingDir string, envVars []string, command string, args ...string) (string, error)

Run the given shell command with the given environment variables and arguments in the given working directory

func ToString added in v0.3.0

func ToString(value interface{}) string

Convert a single value to its string representation

func ToStringList added in v0.3.0

func ToStringList(genericList []interface{}) []string

Convert a generic list to a list of strings

func ToStringMap added in v0.3.0

func ToStringMap(genericMap map[interface{}]interface{}) map[string]string

Convert a generic map to a map from string to string

func ToStringToGenericMap added in v0.3.0

func ToStringToGenericMap(genericMap map[interface{}]interface{}) map[string]interface{}

Convert a generic map to a map from string to interface

func WriteFileWithSamePermissions

func WriteFileWithSamePermissions(source string, destination string, contents []byte) error

Write a file to the given destination with the given contents using the same permissions as the file at source

Types

type NoSuchFile

type NoSuchFile string

func (NoSuchFile) Error

func (path NoSuchFile) Error() string

type ObjectMarshalingErr added in v0.3.6

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

ObjectMarshalingErr is returned when there was an error marshaling the given object to yaml.

func (ObjectMarshalingErr) Error added in v0.3.6

func (err ObjectMarshalingErr) Error() string

type UnmarshalableObjectErr added in v0.3.6

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

UnmarshalableObjectErr is returned when the given object does not implement Marshaler interface.

func (UnmarshalableObjectErr) Error added in v0.3.6

func (err UnmarshalableObjectErr) Error() string

Jump to

Keyboard shortcuts

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