Documentation
¶
Index ¶
- Variables
- type MockService
- func (m *MockService) Confirm(ctx context.Context, prompt, defaultValue string) (bool, error)
- func (m *MockService) Prompt(ctx context.Context, prompt, defaultValue string) (string, error)
- func (m *MockService) Select(ctx context.Context, title, prompt string, options []string, defaultIndex int) (int, error)
- func (m *MockService) SelectString(ctx context.Context, title, prompt string, options []string, ...) (string, error)
- type Service
- func (s *Service) Confirm(ctx context.Context, prompt, defaultValue string) (bool, error)
- func (s *Service) Prompt(ctx context.Context, prompt, defaultValue string) (string, error)
- func (s *Service) Select(ctx context.Context, title, prompt string, options []string, defaultIndex int) (int, error)
- func (s *Service) SelectString(ctx context.Context, title, prompt string, options []string, ...) (string, error)
- type ServiceInterface
- type TestInputService
- func (t *TestInputService) Confirm(_ context.Context, _, _ string) (bool, error)
- func (t *TestInputService) Prompt(_ context.Context, _, defaultValue string) (string, error)
- func (t *TestInputService) Select(_ context.Context, _ string, options []string, defaultIndex int) (int, error)
- func (t *TestInputService) SelectString(_ context.Context, _ string, options []string, defaultValue string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInputCanceled = eris.New("input canceled") ErrInvalidInput = eris.New("invalid input") )
Functions ¶
This section is empty.
Types ¶
type MockService ¶
MockService provides a mock implementation of ServiceInterface for testing.
func (*MockService) Select ¶
func (m *MockService) Select( ctx context.Context, title, prompt string, options []string, defaultIndex int, ) (int, error)
Select mocks the Select method.
func (*MockService) SelectString ¶
func (m *MockService) SelectString( ctx context.Context, title, prompt string, options []string, defaultValue string, ) (string, error)
SelectString mocks the SelectString method.
type Service ¶
type Service struct {
Input io.Reader // Allows injection of different input sources for testing
Output io.Writer // Allows injection of different output destinations for testing
}
Service implements the input interface using standard input/output.
func NewService ¶
func NewService() Service
NewService creates a new input service with standard stdin/stdout.
func NewTestService ¶
NewTestService creates a new input service for testing with custom input/output.
type ServiceInterface ¶
type ServiceInterface interface {
// Prompt displays a prompt and returns user input
Prompt(ctx context.Context, prompt, defaultValue string) (string, error)
// Confirm asks for Y/n confirmation with default
Confirm(ctx context.Context, prompt, defaultValue string) (bool, error)
// Select allows user to select from multiple options by number
Select(ctx context.Context, title, prompt string, options []string, defaultIndex int) (int, error)
// SelectString allows user to select from multiple options, returns the selected string
SelectString(ctx context.Context, title, prompt string, options []string, defaultValue string) (string, error)
}
ServiceInterface defines methods for handling user input.
type TestInputService ¶
type TestInputService struct {
Responses []string // Predefined responses in order
ResponseIndex int // Current index in responses
ConfirmResponse bool // Default confirm response
}
TestInputService provides a simple test implementation with predefined responses.
func NewTestInputService ¶
func NewTestInputService(responses []string) *TestInputService
NewTestInputService creates a new test service with predefined responses.
func (*TestInputService) Select ¶
func (t *TestInputService) Select(_ context.Context, _ string, options []string, defaultIndex int) (int, error)
Select returns the first option by default.
func (*TestInputService) SelectString ¶
func (t *TestInputService) SelectString( _ context.Context, _ string, options []string, defaultValue string, ) (string, error)
SelectString returns the default value or first option.