common

package
v1.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 33 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArgsCompletionFilter = func(cmd *cobra.Command, args []string, toComplete string, completions []string, directive cobra.ShellCompDirective) ([]string, cobra.ShellCompDirective) {
	args = append(args, toComplete)
	err := cmd.Args(cmd, args)
	if err != nil {
		fmt.Println(err.Error())
		return []string{}, cobra.ShellCompDirectiveError
	}

	return completions, directive
}
View Source
var BoolCompletions = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
}
View Source
var BoolValidate = func(bool string) error {
	if bool != "true" && bool != "false" {
		return errors.InvalidArgumentErrorf("invalid boolean value")
	}
	return nil
}
View Source
var BoolValidateOpt = func(inp *textinput.TextInput) {
	inp.Validate = BoolValidate
}
View Source
var InputDefaultOpt = func(def string) GetInputOption {
	return func(inp *textinput.TextInput) {
		inp.InitialValue = def
	}
}
View Source
var NoCompletions = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	return []string{}, cobra.ShellCompDirectiveNoFileComp
}
View Source
var SelectEnableFilterOpt = func(s *selection.Selection[string]) {
	s.Filter = selection.FilterContainsCaseSensitive[string]
}
View Source
var SelectExtendTemplateOpt = func(t template.FuncMap) SelectInputOption {
	return func(s *selection.Selection[string]) {
		s.ExtendedTemplateFuncs = t
	}
}
View Source
var SelectFuzzyFilterOpt = func(s *selection.Selection[string]) {
	s.Filter = func(filter string, choice *selection.Choice[string]) bool {
		return fuzzy.Match(filter, choice.Value)
	}
}
View Source
var SelectTemplateOpt = func(template string) SelectInputOption {
	return func(s *selection.Selection[string]) {
		s.Template = template
	}
}
View Source
var ValidateAbsPathOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateAbsolutePath
}
View Source
var ValidateAbsolutePath = func(input string) error {
	if abs := path.IsAbs(input); !abs {
		return errors.InvalidArgumentErrorf("must be an absolute path")
	}
	return nil
}
View Source
var ValidateAll = func(input string) error {
	return nil
}
View Source
var ValidateAllOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateAll
}
View Source
var ValidateBool = func(s string) error {
	if s == "" {
		return nil
	}

	if _, err := parseBool(s); err != nil {
		return err
	}

	return nil
}
View Source
var ValidateBoolOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateBool
}
View Source
var ValidateEmail = func(input string) error {
	_, err := mail.ParseAddress(input)
	if err != nil {
		return err
	}
	return nil
}
View Source
var ValidateEmailOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateEmail
}
View Source
var ValidateFilePath = func(input string) error {
	if path.Ext(input) == "" {
		return errors.InvalidArgumentErrorf("must be a file path")
	}
	return nil
}
View Source
var ValidateFilePathOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateFilePath
}
View Source
var ValidateImage = func(input string) error {
	_, err := reference.ParseDockerRef(input)
	if err != nil {
		return err
	}

	return nil
}
View Source
var ValidateImageOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateImage
}
View Source
var ValidateInt = func(input string) error {
	_, err := strconv.Atoi(input)
	if err != nil {
		return err
	}
	return nil
}
View Source
var ValidateIntOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateInt
}
View Source
var ValidateNonEmpty = func(input string) error {
	if input == "" {
		return errors.InvalidArgumentErrorf("value cannot be empty")
	}
	return nil
}
View Source
var ValidateNonEmptyOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateNonEmpty
}
View Source
var ValidatePasswordOpt = func(inp *textinput.TextInput) {
	inp.Validate = utils.ValidatePassword
}
View Source
var ValidatePhoneOpt = func(inp *textinput.TextInput) {
	inp.Validate = utils.ValidatePhone
}
View Source
var ValidateQuantity = func(s string) error {
	_, err := resource.ParseQuantity(s)
	return err
}
View Source
var ValidateQuantityOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateQuantity
}
View Source
var ValidateSystemName = func(input string) error {
	if l := len(input); l < 3 || l > 63 {
		return errors.InvalidArgumentErrorf("must be between 3 and 63 characters long")
	}

	if !regexp.MustCompile(`^[a-z][a-z0-9-]+[a-z0-9]$`).MatchString(input) {
		return errors.InvalidArgumentErrorf("invalid name; can only contain a-z, 0-9 and '-'")
	}

	return nil
}
View Source
var ValidateSystemNameOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateSystemName
}
View Source
var ValidateURL = func(input string) error {
	_, err := url.Parse(input)
	return err
}
View Source
var ValidateURLOpt = func(inp *textinput.TextInput) {
	inp.Validate = ValidateURL
}

Functions

func Complete added in v1.2.0

func Complete(base completionBase, filters ...completionFilter) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

Complete is a helper function to chain a completion function and subsequent filters.

func FormatDuration added in v1.2.0

func FormatDuration(d time.Duration) string

func FormatField

func FormatField(s string) string

func FormatIntToSI added in v1.1.3

func FormatIntToSI(n uint64, decimals int) string

func GetDatabase

func GetDatabase(ctx context.Context, identifier string, nc rig.Client) (*database.Database, string, error)

func GetGroup

func GetGroup(ctx context.Context, identifier string, nc rig.Client) (*group.Group, string, error)

func GetStorageProvider

func GetStorageProvider(ctx context.Context, identifier string, nc rig.Client) (*storage.Provider, string, error)

func GetUser

func GetUser(ctx context.Context, identifier string, nc rig.Client) (*user.User, string, error)

func GetUserAndPasswordUpdates

func GetUserAndPasswordUpdates(username, email, phoneNumber, password string) ([]*user.Update, error)

func GetUserIdentifier

func GetUserIdentifier(username, email, phoneNumber string) (*model.UserIdentifier, error)

func GetUserIdentifierUpdates

func GetUserIdentifierUpdates(username, email, phoneNumber string) ([]*user.Update, error)

func MaxArgsCompletionFilter added in v1.2.0

func MaxArgsCompletionFilter(max int) completionFilter

func ParseUserIdentifier

func ParseUserIdentifier(identifier string) (*model.UserIdentifier, error)

func ParseUserIdentifierUpdate

func ParseUserIdentifierUpdate(identifier string) (*user.Update, error)

func PromptConfirm

func PromptConfirm(label string, def bool) (bool, error)

func PromptInput added in v1.1.3

func PromptInput(label string, opts ...GetInputOption) (string, error)

func PromptPassword added in v1.1.3

func PromptPassword(label string) (string, error)

func PromptSelect

func PromptSelect(label string, choices []string, opts ...SelectInputOption) (int, string, error)

func PromptTableSelect added in v1.2.0

func PromptTableSelect(label string, choices [][]string, columnHeaders []string, opts ...SelectInputOption) (int, error)

func PromptUserIndentifier

func PromptUserIndentifier() (*model.UserIdentifier, error)

func PromptUserIndentifierUpdate

func PromptUserIndentifierUpdate() (*user.Update, error)

func ProtoToPrettyJson

func ProtoToPrettyJson(m protoreflect.ProtoMessage) string

func ToStringWithSignificantDigits added in v1.1.3

func ToStringWithSignificantDigits(f float64, digits int) string

Types

type GetInputOption added in v1.1.3

type GetInputOption = func(*textinput.TextInput)

type SelectInputOption added in v1.2.0

type SelectInputOption = func(s *selection.Selection[string])

TODO What about non-string Selection

Jump to

Keyboard shortcuts

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