feat(cli): add tinyforge terminal client
New zero-dependency Go CLI (cmd/cli) that drives the existing HTTP API: login/logout, apps list, deploy (synchronous, --timeout), logs (one-shot + -f SSE follow), and status. Caches a 24h JWT in ~/.tinyforge/config.json (0600, Chmod-enforced on overwrite); Bearer-header auth keeps the token out of server/proxy logs; no-echo password prompt (kernel32 on Windows, stty elsewhere). Server/token resolved via flags, TINYFORGE_URL/TINYFORGE_TOKEN env, or config. README CLI section + root-anchored .gitignore entries for the build output.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// promptPassword reads a password from stdin with echo disabled via stty. If
|
||||
// stty is unavailable (no tty, missing binary), it falls back to an echoed
|
||||
// read so the command still works in pipes/CI.
|
||||
func promptPassword(label string) (string, error) {
|
||||
fmt.Fprint(os.Stderr, label)
|
||||
|
||||
echoDisabled := stty("-echo") == nil
|
||||
if echoDisabled {
|
||||
defer func() {
|
||||
_ = stty("echo")
|
||||
fmt.Fprintln(os.Stderr) // the Enter keystroke was not echoed
|
||||
}()
|
||||
}
|
||||
|
||||
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
if err != nil && line == "" {
|
||||
return "", fmt.Errorf("read password: %w", err)
|
||||
}
|
||||
return strings.TrimRight(line, "\r\n"), nil
|
||||
}
|
||||
|
||||
func stty(arg string) error {
|
||||
cmd := exec.Command("stty", arg)
|
||||
cmd.Stdin = os.Stdin
|
||||
return cmd.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user