Documentation
¶
Index ¶
- Variables
- func AskConfirmation(m ...string) error
- func BackupPasswordConfirmation(message string) (string, error)
- func GetBackupPassphrase(stdIn io.Reader, canPrompt bool, hasStdin bool, message string) (string, error)
- func GetPassphrase(stdIn io.Reader, canPrompt bool, hasStdin bool, message string) (string, error)
- func PasswordConfirmation(message string) (string, error)
- func ValidateBackupPassphrase(passphrase string) error
- type PromptStubber
- type QuestionStub
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoPrompt = errors.New("No prompt stub")
View Source
var PassphraseInvalidMessage = fmt.Sprintf("Passphrase contains invalid characters. Only alphanumeric characters and the folowing special characters are permitted:%v", allowedSpecialChars)
View Source
var PromptConfirm = func(message string, defaultValue bool) (bool, error) { defaultString := "y/N" if defaultValue { defaultString = "Y/n" } messageWithDefault := fmt.Sprintf("%s (%s): ", message, defaultString) m := newTextInputModel(messageWithDefault) p := tea.NewProgram(m) returnedModel, err := p.Run() if err != nil { log.Fatal(err) return false, err } if returnedModel.(textInputModel).textinput.Value() == "" { return defaultValue, nil } return isAffirmative(returnedModel.(textInputModel).textinput.Value()), nil }
View Source
var PromptInput = func(message string) (string, error) { return PromptInputDefault(message, "") }
View Source
var PromptInputDefault = func(message, defaultValue string) (string, error) { m := newTextInputModel(fmt.Sprintf("%s ", message)) m.textinput.SetValue(defaultValue) p := tea.NewProgram(m) returnedModel, err := p.Run() if err != nil { log.Fatal(err) return "", err } return returnedModel.(textInputModel).textinput.Value(), nil }
View Source
var PromptMultiSelectIndex = func(question string, choices []string, preSelected []string) ([]int, error) { result, err := PromptMultiSelection(question, choices, preSelected) if err != nil { return nil, err } var selectedIndices []int j := 0 for i := 0; i < len(choices) && j < len(result); i++ { if choices[i] == result[j] { selectedIndices = append(selectedIndices, i) j++ } } return selectedIndices, nil }
View Source
var PromptMultiSelection = func(question string, choices, preSelected []string) ([]string, error) { result, err := prompt(question, choices, preSelected, false) if err != nil { return nil, err } if len(result) > 0 { return result, nil } return nil, fmt.Errorf("No input provided") }
View Source
var PromptPassword = func(message string) (string, error) { m := newTextInputModel(fmt.Sprintf("%s ", message)) m.textinput.EchoMode = textinput.EchoPassword m.textinput.EchoCharacter, _ = utf8.DecodeLastRuneInString("*") p := tea.NewProgram(m) returnedModel, err := p.Run() if err != nil { log.Fatal(err) return "", err } return returnedModel.(textInputModel).textinput.Value(), nil }
View Source
var PromptSelection = func(question string, choices []string, preSelected string) (string, error) { var result []string var err error if preSelected == "" { result, err = prompt(question, choices, []string{}, true) } else { result, err = prompt(question, choices, []string{preSelected}, true) } if err != nil { return "", err } if len(result) > 0 { return result[0], nil } return "", fmt.Errorf("No input provided") }
View Source
var PromptSelectionIndex = func(question string, choices []string, preSelected string) (int, error) { result, err := prompt(question, choices, []string{preSelected}, true) if err != nil { return -1, err } if len(result) > 0 { for i, name := range choices { if result[0] == name { return i, nil } } } return -1, fmt.Errorf(("No input provided")) }
Functions ¶
func AskConfirmation ¶
AskConfirmation make sure user confirm action, otherwise abort.
func BackupPasswordConfirmation ¶
BackupPasswordConfirmation prompts for a backup passphrase with validation
func GetBackupPassphrase ¶
func GetBackupPassphrase(stdIn io.Reader, canPrompt bool, hasStdin bool, message string) (string, error)
GetBackupPassphrase checks stdin if we have anything, and use that as passphrase otherwise, if we can prompt, prompt user input with validation for backup passphrases
func GetPassphrase ¶
GetPassphrase check stdin if we have anything, and use that as passphrase otherwise, if we can prompt, Prompt user input
func PasswordConfirmation ¶
func ValidateBackupPassphrase ¶
ValidateBackupPassphrase validates that a passphrase contains only allowed characters: alphanumeric characters (a-z, A-Z, 0-9) and common printable special characters. It rejects spaces, tabs, and exotic unicode characters like emojis.
Types ¶
type PromptStubber ¶
type PromptStubber struct {
// contains filtered or unexported fields
}
func InitStubbers ¶
func InitStubbers(t *testing.T) (*PromptStubber, func())
func (*PromptStubber) Stub ¶
func (ps *PromptStubber) Stub(stubbedQuestions []*QuestionStub)
func (*PromptStubber) StubOne ¶
func (ps *PromptStubber) StubOne(value interface{})
func (*PromptStubber) StubPrompt ¶
func (ps *PromptStubber) StubPrompt(msg string) *QuestionStub
type QuestionStub ¶
type QuestionStub struct {
Name string
Value interface{}
Default bool
// contains filtered or unexported fields
}
func (*QuestionStub) AnswerDefault ¶
func (s *QuestionStub) AnswerDefault() *QuestionStub
func (*QuestionStub) AnswerWith ¶
func (s *QuestionStub) AnswerWith(v interface{}) *QuestionStub
Click to show internal directories.
Click to hide internal directories.