common

package
v1.8.17 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 42 Imported by: 10

Documentation

Index

Constants

View Source
const (
	AuthGroupID       = "auth"
	OtherGroupID      = "other"
	CapsuleGroupID    = "capsule"
	ManagementGroupID = "management"
)
View Source
const (
	AuthGroupTitle       = "Authentication Commands - Manage access to Rig"
	OtherGroupTitle      = "Other Commands"
	CapsuleGroupTitle    = "Capsule Commands - Capsules and their deployments"
	ManagementGroupTitle = "Management Commands - Manage everything around capsules"
)

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 {
		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.ShellCompDirectiveDefault
}

Functions

func BoolValidate

func BoolValidate(bool string) error

func BoolValidateOpt added in v1.1.3

func BoolValidateOpt(inp *textinput.TextInput)

func ChainCompletions added in v1.8.12

func ChainCompletions(
	numArgs []int,
	chain ...CompletionBase,
) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

ChainCompletions is a helper function to chain multiple completion functions. i.e. provide a number of arguments from each completion function. numArgs is a running sum of the number of arguments each completion function provides. i.e. [1, 2, 4] means first function provides argument 1, second function provides argument 2, and third function provides arguments 3 and 4. The length of numArgs must match the length of the completion chain.

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 Format added in v1.6.1

func Format(v any, outputType OutputType) (string, error)

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 FormatPrint added in v1.6.1

func FormatPrint(v any, o OutputType) error

func FormatTime added in v1.6.4

func FormatTime(t time.Time) string

func GetAllAnnotations added in v1.6.1

func GetAllAnnotations(cmd *cobra.Command) map[string]string

func GetGroup

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

func GetMember added in v1.6.0

func GetMember(ctx context.Context, rc rig.Client, p Prompter) (string, string, []string, error)

func GetUser

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

func ParseUserIdentifier

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

func RoleCompletions added in v1.6.2

func RoleCompletions(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective)

func SelectDontShowResultOpt added in v1.4.0

func SelectDontShowResultOpt(s *selection.Selection[string])

func SelectEnableFilterOpt added in v1.2.0

func SelectEnableFilterOpt(s *selection.Selection[string])

func SelectFuzzyFilterOpt added in v1.2.0

func SelectFuzzyFilterOpt(s *selection.Selection[string])

func ToStringWithSignificantDigits added in v1.1.3

func ToStringWithSignificantDigits(f float64, digits int) string

func UserIndentifier added in v1.8.11

func UserIndentifier(p Prompter) (*model.UserIdentifier, error)

func ValidateAbsPathOpt added in v1.1.3

func ValidateAbsPathOpt(inp *textinput.TextInput)

func ValidateAbsolutePath added in v1.1.3

func ValidateAbsolutePath(input string) error

func ValidateAll

func ValidateAll(_ string) error

func ValidateAllOpt added in v1.1.3

func ValidateAllOpt(inp *textinput.TextInput)

func ValidateAllowEmpty added in v1.5.2

func ValidateAllowEmpty(validator func(string) error) func(s string) error

func ValidateAnd added in v1.5.2

func ValidateAnd(validators ...func(s string) error) func(s string) error

func ValidateBool added in v1.1.3

func ValidateBool(s string) error

func ValidateBoolOpt added in v1.1.3

func ValidateBoolOpt(inp *textinput.TextInput)

func ValidateCronExpression added in v1.5.2

func ValidateCronExpression(s string) error

func ValidateCronExpressionOpt added in v1.5.2

func ValidateCronExpressionOpt(inp *textinput.TextInput)

func ValidateDuration added in v1.5.2

func ValidateDuration(s string) error

func ValidateDurationOpt added in v1.5.2

func ValidateDurationOpt(inp *textinput.TextInput)

func ValidateEmail

func ValidateEmail(input string) error

func ValidateEmailOpt added in v1.1.3

func ValidateEmailOpt(inp *textinput.TextInput)

func ValidateFilePath added in v1.2.0

func ValidateFilePath(input string) error

func ValidateFilePathOpt added in v1.2.0

func ValidateFilePathOpt(inp *textinput.TextInput)

func ValidateImage

func ValidateImage(input string) error

func ValidateImageOpt added in v1.1.3

func ValidateImageOpt(inp *textinput.TextInput)

func ValidateInt

func ValidateInt(input string) error

func ValidateIntInRange added in v1.5.1

func ValidateIntInRange(minInclusive, maxInclusive int) func(string) error

func ValidateIntOpt added in v1.1.3

func ValidateIntOpt(inp *textinput.TextInput)

func ValidateKubernetesName added in v1.5.1

func ValidateKubernetesName(input string) error

func ValidateKubernetesNameOpt added in v1.5.1

func ValidateKubernetesNameOpt(inp *textinput.TextInput)

func ValidateLength added in v1.5.2

func ValidateLength(minLength, maxLength int) func(string) error

func ValidateNonEmpty

func ValidateNonEmpty(input string) error

func ValidateNonEmptyOpt added in v1.1.3

func ValidateNonEmptyOpt(inp *textinput.TextInput)

func ValidatePasswordOpt added in v1.1.3

func ValidatePasswordOpt(inp *textinput.TextInput)

func ValidatePhoneOpt added in v1.1.3

func ValidatePhoneOpt(inp *textinput.TextInput)

func ValidatePort added in v1.4.0

func ValidatePort(s string) error

func ValidatePortOpt added in v1.4.0

func ValidatePortOpt(inp *textinput.TextInput)

func ValidateQuantity added in v1.1.3

func ValidateQuantity(s string) error

func ValidateQuantityOpt added in v1.1.3

func ValidateQuantityOpt(inp *textinput.TextInput)

func ValidateSystemName

func ValidateSystemName(input string) error

func ValidateSystemNameOpt added in v1.1.3

func ValidateSystemNameOpt(inp *textinput.TextInput)

func ValidateUInt added in v1.5.2

func ValidateUInt(input string) error

func ValidateUIntOpt added in v1.5.2

func ValidateUIntOpt(inp *textinput.TextInput)

func ValidateURL

func ValidateURL(input string) error

func ValidateURLOpt added in v1.1.3

func ValidateURLOpt(inp *textinput.TextInput)

func ValidateURLPathOpt added in v1.5.2

func ValidateURLPathOpt(inp *textinput.TextInput)

func ValidateUnique added in v1.4.0

func ValidateUnique(values []string) func(string) error

Types

type CompletionBase added in v1.5.0

type CompletionBase func(
	cmd *cobra.Command,
	args []string,
	toComplete string,
) ([]string, cobra.ShellCompDirective)

type CompletionFilter added in v1.5.0

type CompletionFilter func(
	cmd *cobra.Command,
	args []string,
	toComplete string,
	current []string,
	directive cobra.ShellCompDirective,
) ([]string, cobra.ShellCompDirective)

func AddValidArgsCompletionFilter added in v1.8.12

func AddValidArgsCompletionFilter(validArgs ...string) CompletionFilter

func MaxArgsCompletionFilter added in v1.2.0

func MaxArgsCompletionFilter(max int) CompletionFilter

type DeferredOutputCommand added in v1.5.0

type DeferredOutputCommand struct {
	// contains filtered or unexported fields
}

func NewDeferredOutputCommand added in v1.7.0

func NewDeferredOutputCommand(displayMessage string) *DeferredOutputCommand

func (*DeferredOutputCommand) Command added in v1.5.0

func (d *DeferredOutputCommand) Command(cmd string, args ...string) *DeferredOutputCommand

func (*DeferredOutputCommand) End added in v1.5.0

func (d *DeferredOutputCommand) End(successful bool)

func (*DeferredOutputCommand) Output added in v1.5.0

func (d *DeferredOutputCommand) Output() ([]byte, error)

func (*DeferredOutputCommand) Run added in v1.5.0

func (d *DeferredOutputCommand) Run() error

func (*DeferredOutputCommand) RunNew added in v1.5.0

func (d *DeferredOutputCommand) RunNew(cmd string, args ...string) error

func (*DeferredOutputCommand) Start added in v1.5.0

func (d *DeferredOutputCommand) Start() error

func (*DeferredOutputCommand) StdinPipe added in v1.5.0

func (d *DeferredOutputCommand) StdinPipe() (io.WriteCloser, error)

func (*DeferredOutputCommand) Wait added in v1.5.0

func (d *DeferredOutputCommand) Wait() error

type GetInputOption added in v1.1.3

type GetInputOption = func(*textinput.TextInput)

func InputDefaultOpt added in v1.1.3

func InputDefaultOpt(def string) GetInputOption

func ValidateAllowEmptyOpt added in v1.5.2

func ValidateAllowEmptyOpt(validator func(string) error) GetInputOption

func ValidateAndOpt added in v1.4.0

func ValidateAndOpt(validators ...func(string) error) GetInputOption

func ValidateIntInRangeOpt added in v1.5.1

func ValidateIntInRangeOpt(minInclusive, maxInclusive int) GetInputOption

func ValidateLengthOpt added in v1.5.2

func ValidateLengthOpt(minLength, maxLength int) GetInputOption

func ValidateUniqueOpt added in v1.4.0

func ValidateUniqueOpt(values []string) GetInputOption

type OutputType added in v1.6.1

type OutputType string
const (
	OutputTypeJSON   OutputType = "json"
	OutputTypeYAML   OutputType = "yaml"
	OutputTypePretty OutputType = "pretty"
)

func (*OutputType) Set added in v1.6.1

func (e *OutputType) Set(v string) error

Set must have pointer receiver so it doesn't change the value of a copy

func (*OutputType) String added in v1.6.1

func (e *OutputType) String() string

String is used both by fmt.Print and by Cobra in help text

func (*OutputType) Type added in v1.6.1

func (e *OutputType) Type() string

Type is only used in help text

type Prompter added in v1.8.10

type Prompter interface {
	Input(label string, opts ...GetInputOption) (string, error)
	Password(label string) (string, error)
	Select(label string, choices []string, opts ...SelectInputOption) (int, string, error)
	Confirm(label string, def bool) (bool, error)
	TableSelect(
		label string,
		choices [][]string,
		columnHeaders []string,
		opts ...SelectInputOption,
	) (int, error)
}

type SelectInputOption added in v1.2.0

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

TODO What about non-string Selection

func SelectExtendTemplateOpt added in v1.2.0

func SelectExtendTemplateOpt(t template.FuncMap) SelectInputOption

func SelectPageSizeOpt added in v1.7.2

func SelectPageSizeOpt(size int) SelectInputOption

func SelectTemplateOpt added in v1.2.0

func SelectTemplateOpt(template string) SelectInputOption

type StandardPrompter added in v1.8.11

type StandardPrompter struct{}

func (StandardPrompter) Confirm added in v1.8.11

func (StandardPrompter) Confirm(label string, def bool) (bool, error)

func (StandardPrompter) Input added in v1.8.11

func (StandardPrompter) Input(label string, opts ...GetInputOption) (string, error)

func (StandardPrompter) Password added in v1.8.11

func (StandardPrompter) Password(label string) (string, error)

func (StandardPrompter) Select added in v1.8.11

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

func (StandardPrompter) TableSelect added in v1.8.11

func (p StandardPrompter) TableSelect(
	label string,
	choices [][]string,
	columnHeaders []string,
	opts ...SelectInputOption,
) (int, error)

Jump to

Keyboard shortcuts

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