Commit 5f72092

Antonio Mika  ·  2026-10-22 10:46:32 -0400 EDT
parent d642d4b
fix(pico): print help for unknown commands and sessions without a pty
1 files changed,  +24, -3
+24, -3
......@@ -6,6 +6,7 @@ import (
66 "encoding/json"
77 "fmt"
88 "log/slog"
9+ "path/filepath"
910 "strings"
1011 "time"
1112
......@@ -194,6 +195,12 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware {
194195 return func(sesh *pssh.SSHServerConnSession) error {
195196 args := sesh.Command()
196197 if len(args) == 0 {
198+ // Without a pty there is no TUI, and the upload middleware would wait on stdin.
199+ if _, _, ok := sesh.Pty(); !ok {
200+ opts := Cmd{Session: sesh}
201+ opts.help()
202+ return nil
203+ }
197204 return next(sesh)
198205 }
199206
......@@ -284,8 +291,6 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware {
284291 sesh.Fatal(err)
285292 }
286293 return nil
287- default:
288- return next(sesh)
289294 }
290295 }
291296
......@@ -309,7 +314,23 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware {
309314 return nil
310315 }
311316
312- return next(sesh)
317+ if passthrough(cmd) {
318+ return next(sesh)
319+ }
320+
321+ opts.help()
322+ sesh.Fatal(fmt.Errorf("unknown command: %s", cmd))
323+ return nil
313324 }
314325 }
315326 }
327+
328+// passthrough reports whether a later middleware handles cmd. Anything else
329+// would reach the upload middleware, which waits on stdin.
330+func passthrough(cmd string) bool {
331+ switch cmd {
332+ case "scp", "rsync", "command":
333+ return true
334+ }
335+ return filepath.Base(cmd) == "authorized_keys"
336+}