44 "fmt"
55 "os"
66 "os/exec"
7+ "os/signal"
78 "strings"
89
910 "github.com/spf13/cobra"
@@ -18,11 +19,18 @@ func gitssh() *cobra.Command {
1819 Hidden : true ,
1920 Short : `Wraps the "ssh" command and uses the coder gitssh key for authentication` ,
2021 RunE : func (cmd * cobra.Command , args []string ) error {
22+ ctx := cmd .Context ()
23+
24+ // Catch interrupt signals as a best-effort attempt to clean
25+ // up the temporary key file.
26+ ctx , stop := signal .NotifyContext (ctx , interruptSignals ... )
27+ defer stop ()
28+
2129 client , err := createAgentClient (cmd )
2230 if err != nil {
2331 return xerrors .Errorf ("create agent client: %w" , err )
2432 }
25- key , err := client .AgentGitSSHKey (cmd . Context () )
33+ key , err := client .AgentGitSSHKey (ctx )
2634 if err != nil {
2735 return xerrors .Errorf ("get agent git ssh token: %w" , err )
2836 }
@@ -45,7 +53,7 @@ func gitssh() *cobra.Command {
4553 }
4654
4755 args = append ([]string {"-i" , privateKeyFile .Name ()}, args ... )
48- c := exec .CommandContext (cmd . Context () , "ssh" , args ... )
56+ c := exec .CommandContext (ctx , "ssh" , args ... )
4957 c .Stderr = cmd .ErrOrStderr ()
5058 c .Stdout = cmd .OutOrStdout ()
5159 c .Stdin = cmd .InOrStdin ()
0 commit comments