@@ -15,6 +15,7 @@ import (
1515 "tailscale.com/tsnet"
1616
1717 cslog "cdr.dev/slog"
18+ csloghuman "cdr.dev/slog/sloggers/sloghuman"
1819 "github.com/coder/coder/v2/agent/agentssh"
1920 "github.com/coder/serpent"
2021 "github.com/coder/wush/cliui"
@@ -23,14 +24,21 @@ import (
2324)
2425
2526func receiveCmd () * serpent.Command {
26- var overlayType string
27+ var (
28+ overlayType string
29+ verbose bool
30+ )
2731 return & serpent.Command {
2832 Use : "receive" ,
2933 Aliases : []string {"host" },
3034 Long : "Runs the wush server. Allows other wush CLIs to connect to this computer." ,
3135 Handler : func (inv * serpent.Invocation ) error {
3236 ctx := inv .Context ()
33- logger := slog .New (slog .NewTextHandler (io .Discard , nil ))
37+ var logSink io.Writer = io .Discard
38+ if verbose {
39+ logSink = inv .Stderr
40+ }
41+ logger := slog .New (slog .NewTextHandler (logSink , nil ))
3442 dm , err := tsserver .DERPMapTailscale (ctx )
3543 if err != nil {
3644 return err
@@ -77,7 +85,12 @@ func receiveCmd() *serpent.Command {
7785
7886 fmt .Println (cliui .Timestamp (time .Now ()), "Wireguard is ready" )
7987
80- sshSrv , err := agentssh .NewServer (ctx , cslog .Make ( /* sloghuman.Sink(os.Stderr)*/ ), prometheus .NewRegistry (), fs , nil )
88+ sshSrv , err := agentssh .NewServer (ctx ,
89+ cslog .Make (csloghuman .Sink (logSink )),
90+ prometheus .NewRegistry (),
91+ fs ,
92+ nil ,
93+ )
8194 if err != nil {
8295 return err
8396 }
@@ -87,14 +100,33 @@ func receiveCmd() *serpent.Command {
87100 return err
88101 }
89102
90- return sshSrv .Serve (ls )
103+ go func () {
104+ fmt .Println (cliui .Timestamp (time .Now ()), "SSH server listening" )
105+ err := sshSrv .Serve (ls )
106+ if err != nil {
107+ logger .Info ("ssh server exited" , "err" , err )
108+ }
109+ }()
110+
111+ ctx , ctxCancel := inv .SignalNotifyContext (ctx , os .Interrupt )
112+ defer ctxCancel ()
113+
114+ <- ctx .Done ()
115+ return sshSrv .Close ()
91116 },
92117 Options : []serpent.Option {
93118 {
94119 Flag : "overlay-type" ,
95120 Default : "derp" ,
96121 Value : serpent .EnumOf (& overlayType , "derp" , "stun" ),
97122 },
123+ {
124+ Flag : "verbose" ,
125+ FlagShorthand : "v" ,
126+ Description : "Enable verbose logging." ,
127+ Default : "false" ,
128+ Value : serpent .BoolOf (& verbose ),
129+ },
98130 },
99131 }
100132}
0 commit comments