From 6b34fa2a274dda76349d3fab84c11297a2b40446 Mon Sep 17 00:00:00 2001 From: Jason Lunz Date: Mon, 20 Dec 2021 11:38:51 -0700 Subject: [PATCH] oh look, struct definitions can be scoped! --- pkg/cmd/codespace/ssh.go | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pkg/cmd/codespace/ssh.go b/pkg/cmd/codespace/ssh.go index be19eb3f9..66dae59d9 100644 --- a/pkg/cmd/codespace/ssh.go +++ b/pkg/cmd/codespace/ssh.go @@ -190,6 +190,12 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions, execut return fmt.Errorf("error getting codespace info: %w", err) } + type sshResult struct { + codespace *api.Codespace + user string // on success, the remote ssh username; else nil + err error + } + sshUsers := make(chan sshResult) fetches := 0 var status error @@ -258,6 +264,24 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions, execut continue } + // codespaceSSHConfig contains values needed to write an OpenSSH host + // configuration for a single codespace. For example: + // + // Host {{Name}}.{{EscapedRef} + // User {{SSHUser} + // ProxyCommand {{GHExec}} cs ssh -c {{Name}} --stdio + // + // EscapedRef is included in the name to help distinguish between codespaces + // when tab-completing ssh hostnames. '/' characters in EscapedRef are + // flattened to '-' to prevent problems with tab completion or when the + // hostname appears in ControlMaster socket paths. + type codespaceSSHConfig struct { + Name string // the codespace name, passed to `ssh -c` + EscapedRef string // the currently checked-out branch + SSHUser string // the remote ssh username + GHExec string // path used for invoking the current `gh` binary + } + conf := codespaceSSHConfig{ Name: result.codespace.Name, EscapedRef: strings.ReplaceAll(result.codespace.GitStatus.Ref, "/", "-"), @@ -272,30 +296,6 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions, execut return status } -type sshResult struct { - codespace *api.Codespace - user string // on success, the remote ssh username; else nil - err error -} - -// codespaceSSHConfig contains values needed to write an OpenSSH host -// configuration for a single codespace. For example: -// -// Host {{Name}}.{{EscapedRef} -// User {{SSHUser} -// ProxyCommand {{GHExec}} cs ssh -c {{Name}} --stdio -// -// EscapedRef is included in the name to help distinguish between codespaces -// when tab-completing ssh hostnames. '/' characters in EscapedRef are -// flattened to '-' to prevent problems with tab completion or when the -// hostname appears in ControlMaster socket paths. -type codespaceSSHConfig struct { - Name string // the codespace name, passed to `ssh -c` - EscapedRef string // the currently checked-out branch - SSHUser string // the remote ssh username - GHExec string // path used for invoking the current `gh` binary -} - func (a *App) openSSHSession(ctx context.Context, codespace *api.Codespace, liveshareLogger *log.Logger) (*liveshare.Session, error) { if liveshareLogger == nil { liveshareLogger = noopLogger()