Skip to content

Commit 77c342a

Browse files
committed
feat(prompt): add Password method for masked secret input
1 parent 3239333 commit 77c342a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

cli/prompt/prompt.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Prompter interface {
1111
Select(message, defaultValue string, options []string) (int, error)
1212
MultiSelect(message, defaultValue string, options []string) ([]int, error)
1313
Input(message, defaultValue string) (string, error)
14+
Password(message string) (string, error)
1415
Confirm(message string, defaultValue bool) (bool, error)
1516
}
1617

@@ -110,6 +111,27 @@ func (p *huhPrompter) Input(message, defaultValue string) (string, error) {
110111
return result, nil
111112
}
112113

114+
// Password prompts the user for a secret input. The input is masked.
115+
//
116+
// Parameters:
117+
// - message: The prompt message to display.
118+
//
119+
// Returns:
120+
// - The user's input as a string.
121+
// - An error, if any.
122+
func (p *huhPrompter) Password(message string) (string, error) {
123+
var result string
124+
err := huh.NewInput().
125+
Title(message).
126+
Value(&result).
127+
EchoMode(huh.EchoModePassword).
128+
Run()
129+
if err != nil {
130+
return "", fmt.Errorf("prompt error: %w", err)
131+
}
132+
return result, nil
133+
}
134+
113135
// Confirm prompts the user for a yes/no confirmation.
114136
//
115137
// Parameters:

0 commit comments

Comments
 (0)