util

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 13 Imported by: 44

Documentation

Index

Constants

View Source
const (
	TagPrefix = "v"
)

Variables

This section is empty.

Functions

func AddTagPrefix

func AddTagPrefix(tag string) string

func Ask

func Ask(question, expectedResponse string, retries int) (answer string, success bool, err error)

Ask asks the user a question, expecting a known response expectedResponse

You may specify a single response as a string or a series of valid/invalid responses with an optional default.

To specify the valid responses, either pass a string or craft a series of answers using the following format:

"|successAnswers|nonSuccessAnswers|defaultAnswer"

The successAnswers and nonSuccessAnswers can be either a string or a series os responses like:

"|opt1a:opt1b|opt2a:opt2b|defaultAnswer"

This example will accept opt1a and opt1b as successful answers, opt2a and opt2b as unsuccessful answers and in case of an empty answer, it will return "defaultAnswer" as success.

To consider the default as a success, simply list them with the rest of the non successful answers.

func CleanLogFile

func CleanLogFile(logPath string) (err error)

CleanLogFile cleans control characters and sensitive data from a file

func CopyDirContentsLocal

func CopyDirContentsLocal(src, dst string) error

CopyDirContentsLocal copies local directory contents from one local location to another.

func CopyFileLocal

func CopyFileLocal(src, dst string, required bool) error

CopyFileLocal copies a local file from one local location to another.

func Exists

func Exists(path string) bool

Exists indicates whether a file exists.

func MoreRecent

func MoreRecent(a, b string) (bool, error)

MoreRecent determines if file at path a was modified more recently than file at path b. If one file does not exist, the other will be treated as most recent. If both files do not exist or an error occurs, an error is returned.

func PackagesAvailable

func PackagesAvailable(packages ...string) (bool, error)

PackagesAvailable takes a slice of packages and determines if they are installed on the host OS. Replaces common::check_packages.

func RemoveAndReplaceDir

func RemoveAndReplaceDir(path string) error

RemoveAndReplaceDir removes a directory and its contents then recreates it.

func SemverToTagString

func SemverToTagString(tag semver.Version) string

func StripControlCharacters

func StripControlCharacters(logData []byte) []byte

StripControlCharacters takes a slice of bytes and removes control characters and bare line feeds (ported from the original bash anago)

func StripSensitiveData

func StripSensitiveData(logData []byte) []byte

StripSensitiveData removes data deemed sensitive or non public from a byte slice (ported from the original bash anago)

func TagStringToSemver

func TagStringToSemver(tag string) (semver.Version, error)

func TrimTagPrefix

func TrimTagPrefix(tag string) string

func WrapText

func WrapText(originalText string, lineSize int) (wrappedText string)

WrapText wraps a text

Types

type UserInputError

type UserInputError struct {
	ErrorString string
	// contains filtered or unexported fields
}

UserInputError a custom error to handle more user input info

func NewUserInputError

func NewUserInputError(message string, ctrlC bool) UserInputError

NewUserInputError creates a new UserInputError

func (UserInputError) Error

func (e UserInputError) Error() string

Error return the error string

func (UserInputError) IsCtrlC

func (e UserInputError) IsCtrlC() bool

IsCtrlC return true if the user has hit Ctrl+C

Jump to

Keyboard shortcuts

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