feat(cli): add interactive config input and Makefile

- support interactive value input for `config set`
- hide API key input and output
- add Makefile for build, test, vet, coverage, and cleanup
- add golang.org/x/term dependency
- update changelog and gitignore
This commit is contained in:
2026-08-13 13:10:53 +08:00
parent 627ea7110a
commit f04bad5f18
7 changed files with 129 additions and 5 deletions
+43
View File
@@ -0,0 +1,43 @@
package config
import (
"bufio"
"fmt"
"os"
"golang.org/x/term"
)
// ReadSecret prompts the user with msg and reads a line from stdin.
// When stdin is a terminal, echo is disabled so the typed value stays
// invisible. When stdin is piped (non-TTY) it falls back to a normal
// read so scripting still works.
func ReadSecret(msg string) (string, error) {
fmt.Fprint(os.Stderr, msg)
var value string
if term.IsTerminal(int(os.Stdin.Fd())) {
b, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
}
value = string(b)
} else {
sc := bufio.NewScanner(os.Stdin)
if !sc.Scan() {
return "", sc.Err()
}
value = sc.Text()
}
fmt.Fprintln(os.Stderr)
return value, nil
}
// ReadLine prompts the user with msg and reads a normal (echo-enabled) line.
func ReadLine(msg string) (string, error) {
fmt.Fprint(os.Stderr, msg)
sc := bufio.NewScanner(os.Stdin)
if !sc.Scan() {
return "", sc.Err()
}
return sc.Text(), nil
}