prompt

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package prompt is a generated GoMock package.

Index

Constants

View Source
const (
	// ConfirmYes can be used with YesOrNoPrompt to create a confirmation dialog.
	ConfirmYes = "Yes"

	// ConfirmNo can be used with YesOrNoPrompt to create a confirmation dialog.
	ConfirmNo = "No"
)
View Source
const (

	// ErrExitConsoleMessage is the message that is displayed when the user exits the console. This is exported for use in tests.
	ErrExitConsoleMessage = "exiting command"
)

Variables

This section is empty.

Functions

func ValidateKubernetesNamespace

func ValidateKubernetesNamespace(input string) error

ValidateKubernetesNamespace checks if the input string is a valid Kubernetes namespace name, and returns an error if it is not.

func ValidateKubernetesNamespaceOrDefault

func ValidateKubernetesNamespaceOrDefault(input string) error

ValidateKubernetesNamespaceOrDefault checks if the input is an empty string, and if so, returns nil, otherwise it calls ValidateKubernetesNamespace and returns the result. If ValidateKubernetesNamespace returns an error, ValidateKubernetesNamespaceOrDefault will also return an error.

func ValidateResourceName

func ValidateResourceName(input string) error

ValidateResourceName checks if the given string is a valid resource name, and returns an error if it is not.

func ValidateResourceNameOrDefault

func ValidateResourceNameOrDefault(input string) error

ValidateResourceNameOrDefault checks if the input string is empty, and if it is, returns nil, otherwise it calls the ValidateResourceName function to check if the input string is valid.

func ValidateUUIDv4

func ValidateUUIDv4(input string) error

ValidateUUIDv4 checks if the input string is a valid UUIDv4 and returns an error if it is not.

func YesOrNoPrompt

func YesOrNoPrompt(promptMsg string, defaultString string, prompter Interface) (bool, error)

YesOrNoPrompt takes in a prompt message, a default string and a prompter interface, and returns a boolean value and an error if one occurs. It checks if the default string is equal to "yes", and if so, sets the value list to ["yes", "no"], otherwise it sets the value list to ["no", "yes"]. It then gets a list input from the prompter interface, and returns true if the input is equal to "yes", and false otherwise.

Types

type ErrExitConsole

type ErrExitConsole struct {
}

ErrExitConsole represents interrupt commands being entered.

func (*ErrExitConsole) Error

func (e *ErrExitConsole) Error() string

Error returns the error message.

func (*ErrExitConsole) Is

func (e *ErrExitConsole) Is(target error) bool

Is checks for the error type is ErrExitConsole.

func (*ErrExitConsole) IsFriendlyError

func (*ErrExitConsole) IsFriendlyError() bool

IsFriendlyError returns true. Cancelling a command prompt should always be handled gracefully by the CLI.

type ErrUnsupportedModel

type ErrUnsupportedModel struct {
	Message string
}

ErrUnsupportedModel represents error when invalid bubble tea model is used for operations.

func (*ErrUnsupportedModel) Error

func (e *ErrUnsupportedModel) Error() string

ErrUnsupportedModel returns the error message.

func (*ErrUnsupportedModel) Is

func (e *ErrUnsupportedModel) Is(target error) bool

Is checks if the error provided is of type ErrUnsupportedModel.

type Impl

type Impl struct{}

Impl implements BubbleTeaPrompter

func (*Impl) GetListInput

func (i *Impl) GetListInput(items []string, promptMsg string) (string, error)

GetListInput displays a list of strings to the user and returns the user's selection as a string, or an error if the user exits the console or an unsupported model is encountered.

func (*Impl) GetTextInput

func (i *Impl) GetTextInput(prompt string, options TextInputOptions) (string, error)

GetTextInput takes a prompt string and a set of options, and returns a string or an error if the user exits the console or an unsupported model is encountered.

func (*Impl) RunProgram

func (i *Impl) RunProgram(program *tea.Program) (tea.Model, error)

RunProgram runs a bubbletea program and blocks until the program exits.

type Interface

type Interface interface {
	// GetTextInput prompts user for a text input. Will return ErrExitConsole if the user cancels.
	GetTextInput(prompt string, options TextInputOptions) (string, error)

	// GetListInput prompts user to select from a list. Will return ErrExitConsole if the user cancels.
	GetListInput(items []string, promptMsg string) (string, error)

	// RunProgram runs a bubbletea program and blocks until the program exits.
	//
	// To create a cancellable program, use the options to pass a context.Context into the program.
	RunProgram(program *tea.Program) (tea.Model, error)
}

Interface contains operation to prompt the user interactively.

All functions on Interface returns an *ErrExitConsole if the user cancels. This is a friendly error and does not need special handling by calling code.

type MockInterface

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

MockInterface is a mock of Interface interface.

func NewMockInterface

func NewMockInterface(ctrl *gomock.Controller) *MockInterface

NewMockInterface creates a new mock instance.

func (*MockInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockInterface) GetListInput

func (m *MockInterface) GetListInput(arg0 []string, arg1 string) (string, error)

GetListInput mocks base method.

func (*MockInterface) GetTextInput

func (m *MockInterface) GetTextInput(arg0 string, arg1 text.TextModelOptions) (string, error)

GetTextInput mocks base method.

func (*MockInterface) RunProgram

func (m *MockInterface) RunProgram(arg0 *tea.Program) (tea.Model, error)

RunProgram mocks base method.

type MockInterfaceMockRecorder

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

MockInterfaceMockRecorder is the mock recorder for MockInterface.

func (*MockInterfaceMockRecorder) GetListInput

func (mr *MockInterfaceMockRecorder) GetListInput(arg0, arg1 interface{}) *gomock.Call

GetListInput indicates an expected call of GetListInput.

func (*MockInterfaceMockRecorder) GetTextInput

func (mr *MockInterfaceMockRecorder) GetTextInput(arg0, arg1 interface{}) *gomock.Call

GetTextInput indicates an expected call of GetTextInput.

func (*MockInterfaceMockRecorder) RunProgram

func (mr *MockInterfaceMockRecorder) RunProgram(arg0 interface{}) *gomock.Call

RunProgram indicates an expected call of RunProgram.

type TextInputOptions

type TextInputOptions = text.TextModelOptions

TextInputOptions contains options for 'Interface.GetTextInput'.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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