util

package
v0.0.0-...-8f52349 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PrefixColor should be used when adding color to the prefix of a line
	// (e.g., [some-prefix]).
	PrefixColor = color.New(color.FgHiBlue, color.Bold)
	// LabelColor is used for the prompt and select labels.
	LabelColor = color.New(color.FgHiYellow, color.Bold)
	// BenchmarkColor is used for the commands to report how long they took.
	BenchmarkColor = color.New(color.FgHiGreen, color.Bold)
)
View Source
var (
	// NameRegexp ensures a reasonable name.
	NameRegexp = regexp.MustCompile(`^[a-z][0-9a-zA-Z-]{5,29}$`)
	// HostnameRegexp is from https://stackoverflow.com/a/106223
	HostnameRegexp = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
)

Functions

func Command

func Command(ctx context.Context, name string, args ...string) ([]string, error)

Command runs a command with the given context and returns the output's lines. If the command fails, then the output is logged. If the context has verbose set, then the command is logged before being ran.

func Git

func Git(ctx context.Context, args ...string) ([]string, error)

Git will run the command and block until its done.

func HostnamePrompt

func HostnamePrompt(ctx context.Context, label, def string) (string, error)

HostnamePrompt asks the user to enter a hostname. It validates it using HostnameRegexp.

func Kubectl

func Kubectl(ctx context.Context, args ...string) ([]string, error)

Kubectl will run the command and block until its done.

func Logf

func Logf(ctx context.Context, v string, args ...interface{})

Logf reads the settings from the given context and logs the given message.

func NamePrompt

func NamePrompt(ctx context.Context, label, def string) (string, error)

NamePrompt asks the user to enter a name. It validates it using NameRegexp.

func RandName

func RandName(prefix string, args ...interface{}) string

RandName is a utility function that returns a random name for things like spaces or projects.

func Searcher

func Searcher(items []string) func(input string, index int) bool

Searcher implements list.Searcher for promptui.Select. It is case insensitive and returns true only if the input string is present.

func SelectPrompt

func SelectPrompt(
	ctx context.Context,
	label string,
	items ...string,
) (int, string, error)

SelectPrompt prompts the user to select from the given items. It uses Searcher and properly colors the label.

func SelectYesNo

func SelectYesNo(ctx context.Context, label string) (bool, error)

SelectYesNo promts the user to select between yes and no. It will return true if the user selects "yes", and false otherwise.

func SetContextOutput

func SetContextOutput(ctx context.Context, out io.Writer) context.Context

SetContextOutput returns a context that holds where Logf should write.

func SetLogPrefix

func SetLogPrefix(ctx context.Context, prefix string) context.Context

SetLogPrefix returns a context with the desired prefix that Logf will use.

func SetVerbosity

func SetVerbosity(ctx context.Context, verbose bool) context.Context

SetVerbosity returns a context with the desired verbose setting used with Command.

func SetupSpace

func SetupSpace(ctx context.Context, containerRegistry string) error

SetupSpace asks the user if they would like to create a space.

Types

This section is empty.

Jump to

Keyboard shortcuts

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