util

package
v3.0.0-...-c77a060 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExitCodeUsageDisplayed is returned when some usage info / help page was displayed. Unsure whether it should == E_SUCCESS or not
	ExitCodeUsageDisplayed ExitCode = 0
	// ExitCodeSuccess is used to say everything went well
	ExitCodeSuccess = 0
	// ExitCodeTrappedInterrupt is the exit code returned when an unexpected interrupt like SIGUSR1 was trapped
	ExitCodeTrappedInterrupt = -1
	// ExitCodeClientBug is the exit code returned when bytemark-client knows it's faulty
	ExitCodeClientBug = 1
	// ExitCodeCantReadConfig is the exit code returned when we couldn't read a config variable from the disk for some reason
	ExitCodeCantReadConfig = 3
	// ExitCodeCantWriteConfig is the exit code returned when we couldn't write a config variable to the disk for some reason
	ExitCodeCantWriteConfig = 4
	// ExitCodeUserExit is the exit code returned when the user's action caused the program to terminate (usually by saying no to a prompt)
	ExitCodeUserExit = 5
	// ExitCodeWontDeletePopulated is the exit code returned when the user's requested that a group be deleted when it still had servers in
	ExitCodeWontDeletePopulated = 6
	// ExitCodeBadInput is the exit code returned when the user entered a malformed command, name, or flag.
	ExitCodeBadInput = 7
	// ExitCodeSubprocessFailed is the exit code returned when the client attempted to run a subprocess (e.g. ssh, a browser or a vpn client) but couldn't
	ExitCodeSubprocessFailed = 8

	// ExitCodeNoDefaultAccount is the exit code returned when the client couldn't determine a default account. In this situation, the user should manually specify the account to use with the --account flag or using `bytemark config set account`
	ExitCodeNoDefaultAccount = 9

	// ExitCodeUnknownError is the exit code returned when we got an error we couldn't deal with.
	ExitCodeUnknownError = 49

	// ExitCodeCantConnectAuth is the exit code returned when we were unable to establish an HTTP connection to the auth endpoint.
	ExitCodeCantConnectAuth = 50
	// ExitCodeCantConnectAPI is the exit code returned when we were unable to establish an HTTP connection to the API endpoint.
	ExitCodeCantConnectAPI = 150

	// ExitCodeAuthInternalError is the exit code returned when the auth server reported an internal error.
	ExitCodeAuthInternalError = 51
	// ExitCodeAPIInternalError is the exit code returned when the API server reported an internal error.
	ExitCodeAPIInternalError = 152

	// ExitCodeCantParseAuthResponse is the exit code returned when the auth server returned something we were unable to parse.
	ExitCodeCantParseAuthResponse = 52
	// ExitCodeCantParseAPIResponse is the exit code returned when the API server returned something we were unable to parse.
	ExitCodeCantParseAPIResponse = 152

	// ExitCodeInvalidCredentials is the exit code returned when the auth server says your credentials contain invalid characters.
	ExitCodeInvalidCredentials = 53
	// ExitCodeBadCredentials is the exit code returned when the auth server says your credentials don't match a user in its database.
	ExitCodeBadCredentials = 54

	// ExitCodeActionNotPermitted is the exit code returned when the API server says you haven't got permission to do that.
	ExitCodeActionNotPermitted = 155

	// ExitCodeNotFound is the exit code returned when the API server says you do not have permission to see the object you are trying to view, or that it does not exist.
	ExitCodeNotFound = 156

	// ExitCodeBadRequest is the exit code returned when we send a bad request to API. (E.g. names being too short or having wrong characters in)
	ExitCodeBadRequest = 157

	// ExitCodeUnknownAuthError is the exit code returned when we get an unexpected error from the auth server.
	ExitCodeUnknownAuthError = 149
	// ExitCodeUnknownAPIError is the exit code returned when we get an unexpected error from the Bytemark API.
	ExitCodeUnknownAPIError = 249
)

Variables

This section is empty.

Functions

func CallBrowser

func CallBrowser(url string) error

CallBrowser opens the user's desktop browser to the given URL. It tries really hard - first trying open on mac or xdg-open on other systems. If xdg-open couldn't be used, it attempts to use /usr/bin/x-www-browser

func GeneratePassword

func GeneratePassword() (pass string)

GeneratePassword generates a random 16-character password made entirely of letters.

func ParseDiscSpec

func ParseDiscSpec(spec string) (*brain.Disc, error)

ParseDiscSpec reads the given string and attempts to interpret it as a disc spec.

func PromptValidate

func PromptValidate(p Prompter, prompt string, valid func(string) bool) (input string)

PromptValidate prompts for input, validates it. Repeats until the input is actually valid. Returns the valid input.

func PromptYesNo

func PromptYesNo(p Prompter, prompt string) bool

PromptYesNo provides a y/n prompt. Returns true if the user enters y, false otherwise.

func Promptf

func Promptf(p Prompter, promptFormat string, values ...interface{}) string

Promptf formats its arguments with fmt.Sprintf, prompts for input and then returns it.

func PromptfValidate

func PromptfValidate(p Prompter, valid func(string) (bool, string), prompt string, values ...interface{}) (input string)

PromptfValidate uses prompt as a format string, values as the values for the prompt, then prompts for input. The input is then validated using the validation function, and if the input is invalid, it repeats the prompting. Returns the valid input once valid input is put in.

func ValidCreditCard

func ValidCreditCard(input string) (bool, string)

ValidCreditCard is a credit-card-looking bunch of numbers. Doesn't check the check digit.

func ValidEmail

func ValidEmail(input string) (bool, string)

ValidEmail checks that the input looks vaguely like an email address. It's very loose, relies on better validation elsewhere.

func ValidExpiry

func ValidExpiry(input string) (bool, string)

ValidExpiry checks that the input is a valid credit card expiry, written in MMYY format.

func ValidName

func ValidName(input string) (bool, string)

ValidName checks to see that the input looks like a name. Names can't have spaces in, that's all I know.

Types

type DiscSpecError

type DiscSpecError struct {
	Position  int
	Character rune
}

DiscSpecError represents an error during parse.

func (*DiscSpecError) Error

func (e *DiscSpecError) Error() string

type ExitCode

type ExitCode int

ExitCode is a named type for the E_* constants which are used as exit codes.

func HelpForExitCodes

func HelpForExitCodes() ExitCode

HelpForExitCodes prints readable information on what the various exit codes do.

func ProcessError

func ProcessError(err error, message ...string) ExitCode

ProcessError processes the given error, outputs a message, and returns the relevant ExitCode for the given error.

type Prompter

type Prompter interface {
	Prompt(prompt string) (input string)
}

Prompter is an object responsible for prompting the user for input

func NewPrompter

func NewPrompter() Prompter

NewPrompter creates a Prompter which uses stderr and stdin for output and input respectively.

type RecursiveDeleteGroupError

type RecursiveDeleteGroupError struct {
	Group lib.GroupName
	// Map of VirtualMachine names to the error that occurred when trying to delete them.
	// N.B. that this will not contain nil errors for VMs that were successfully deleted.
	Errors map[string]error
}

RecursiveDeleteGroupError is returned by delete group when called with --recursive, when deleting VMs.

func (RecursiveDeleteGroupError) Error

type SubprocessFailedError

type SubprocessFailedError struct {
	Args     []string
	ExitCode int
	Err      error
}

SubprocessFailedError is returned when a process run by bytemark-client (e.g. open/xdg-open to open a browser) failed

func (SubprocessFailedError) Error

func (e SubprocessFailedError) Error() string

type UsageDisplayedError

type UsageDisplayedError struct {
	TheProblem string
	Command    string
}

UsageDisplayedError is returned by commands when the user entered wrong info and the help was output

func (UsageDisplayedError) Error

func (e UsageDisplayedError) Error() string

type UserRequestedExit

type UserRequestedExit struct{}

UserRequestedExit is returned when the user said 'No' to a 'yes/no' prompt.

func (UserRequestedExit) Error

func (e UserRequestedExit) Error() string

type WontDeleteGroupWithVMsError

type WontDeleteGroupWithVMsError struct {
	Group lib.GroupName
}

WontDeleteGroupWithVMsError is returned when 'delete group' was called on a group with stuff in, without --recursive being specified

func (WontDeleteGroupWithVMsError) Error

Directories

Path Synopsis
Package sizespec implements a parser for size specifications.
Package sizespec implements a parser for size specifications.

Jump to

Keyboard shortcuts

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