CI / Test (linux/amd64) (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Cross-build (darwin/amd64) (push) Waiting to run
CI / Cross-build (linux/amd64) (push) Waiting to run
CI / Cross-build (darwin/arm64) (push) Waiting to run
CI / Cross-build (linux/arm64) (push) Waiting to run
- Migrate .golangci.yml to golangci-lint v2 config format - Bump golangci-lint-action from v6 (Node 20, deprecated) to v9 (Node 24) - Fix errcheck: check fmt.Fscanln and fmt.Sscanf return values - Fix ineffassign: replace unused vars with _ in test files - Fix revive unused-parameter: rename unused cmd/args/r/c params to _ - Fix revive empty-block: invert if condition in push command - Fix revive redefines-builtin-id: rename 'clear' to 'clearsigned' - Fix revive blank-imports: add comment on modernc.org/sqlite import - Fix unused: remove unused 'suite' and 'gen' fields from cache entry
41 lines
962 B
Go
41 lines
962 B
Go
// Package interact provides simple interactive prompts (passwords, confirms).
|
|
package interact
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
// ReadPassword prompts for a password with input hidden.
|
|
func ReadPassword(prompt string) (string, error) {
|
|
fmt.Fprint(os.Stderr, prompt)
|
|
b, err := term.ReadPassword(int(os.Stdin.Fd()))
|
|
fmt.Fprintln(os.Stderr)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
// ReadLine prompts and reads a single line of input.
|
|
func ReadLine(prompt string) (string, error) {
|
|
fmt.Fprint(os.Stderr, prompt)
|
|
var s string
|
|
if _, err := fmt.Fscanln(os.Stdin, &s); err != nil {
|
|
return "", err
|
|
}
|
|
return strings.TrimSpace(s), nil
|
|
}
|
|
|
|
// Confirm prompts a yes/no question, returning the boolean answer.
|
|
func Confirm(prompt string) bool {
|
|
fmt.Fprintf(os.Stderr, "%s [y/N]: ", prompt)
|
|
var s string
|
|
_, _ = fmt.Fscanln(os.Stdin, &s)
|
|
s = strings.ToLower(strings.TrimSpace(s))
|
|
return s == "y" || s == "yes"
|
|
}
|