jsonpaths: auto-enable anonymous mode when no TTY

When input is piped (CI, scripts, AI agents), /dev/tty won't exist.
Previously this crashed with 'cannot open /dev/tty'. Now we detect
the absence of a TTY and auto-enable --anonymous mode.
This commit is contained in:
AJ ONeal 2026-06-11 16:38:34 -06:00
parent aab60c7ac2
commit fabd193884
No known key found for this signature in database

View File

@ -89,6 +89,15 @@ func main() {
fs.BoolVar(&cfg.noCache, "no-cache", false, "skip local cache for URL inputs")
fs.StringVar(&cfg.user, "user", "", "HTTP basic auth (user:password, like curl)")
// Auto-enable anonymous mode when there's no TTY (piped input, CI, etc.).
if !cfg.anonymous {
if f, err := os.Open("/dev/tty"); err != nil {
cfg.anonymous = true
} else {
f.Close()
}
}
// Handle version/help before flag parse
if len(os.Args) > 1 {
switch os.Args[1] {