util

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// KubebuilderBinName define the name of the kubebuilder binary to be used in the tests
	KubebuilderBinName = "kubebuilder"
)

Variables

This section is empty.

Functions

func AppendCodeAtTheEnd

func AppendCodeAtTheEnd(filename, code string) error

AppendCodeAtTheEnd appends the given code at the end of the file.

func AppendCodeIfNotExist

func AppendCodeIfNotExist(filename, code string) error

AppendCodeIfNotExist checks if the code does not already exist in the file, and if not, appends it to the end.

func CommentCode added in v4.1.0

func CommentCode(filename, target, prefix string) error

CommentCode searches for target in the file and adds the comment prefix to the target content. The target content may span multiple lines.

func EnsureExistAndReplace

func EnsureExistAndReplace(input, match, replace string) (string, error)

EnsureExistAndReplace check if the content exists and then do the replace

func GetNonEmptyLines

func GetNonEmptyLines(output string) []string

GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it.

func HasFileContentWith

func HasFileContentWith(path, text string) (bool, error)

HasFileContentWith check if given `text` can be found in file

func HasFragment

func HasFragment(path, target string) (bool, error)

func ImplementWebhooks

func ImplementWebhooks(filename string) error

ImplementWebhooks will mock an webhook data

func InsertCode

func InsertCode(filename, target, code string) error

InsertCode searches target content in the file and insert `toInsert` after the target.

func InsertCodeIfNotExist

func InsertCodeIfNotExist(filename, target, code string) error

InsertCodeIfNotExist insert code if it does not already exists

func RandomSuffix

func RandomSuffix() (string, error)

RandomSuffix returns a 4-letter string.

func ReplaceInFile

func ReplaceInFile(path, old, new string) error

ReplaceInFile replaces all instances of old with new in the file at path.

func ReplaceRegexInFile

func ReplaceRegexInFile(path, match, replace string) error

ReplaceRegexInFile finds all strings that match `match` and replaces them with `replace` in the file at path.

func RunCmd

func RunCmd(msg, cmd string, args ...string) error

RunCmd prints the provided message and command and then executes it binding stdout and stderr

func UncommentCode

func UncommentCode(filename, target, prefix string) error

UncommentCode searches for target in the file and remove the comment prefix of the target content. The target content may span multiple lines.

func YesNo

func YesNo(reader *bufio.Reader) bool

YesNo reads from stdin looking for one of "y", "yes", "n", "no" and returns true for "y" and false for "n"

Types

This section is empty.

Jump to

Keyboard shortcuts

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