From b2598d64f97a59558e06cd58ea21ebdf50e78e9d Mon Sep 17 00:00:00 2001 From: Jason Lunz Date: Fri, 17 Dec 2021 16:57:29 -0700 Subject: [PATCH] start codespace to fetch config if it's explicitly requested When running `gh cs ssh config` without a `-c` option, we skip codespaces that aren't available. This change suppresses that behavior when a single codespace is explicitly requested, starting the codespace if it's not running. --- pkg/cmd/codespace/ssh.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/codespace/ssh.go b/pkg/cmd/codespace/ssh.go index 5dc4050a6..6349db5fc 100644 --- a/pkg/cmd/codespace/ssh.go +++ b/pkg/cmd/codespace/ssh.go @@ -194,7 +194,7 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions) error fetches := 0 var status error for _, cs := range codespaces { - if cs.State != "Available" { + if cs.State != "Available" && opts.codespace == "" { fmt.Fprintf(os.Stderr, "skipping unavailable codespace %s: %s\n", cs.Name, cs.State) status = cmdutil.SilentError continue @@ -423,7 +423,7 @@ func newConfigCmd(app *App) *cobra.Command { configCmd := &cobra.Command{ Use: "config [-c codespace]", Short: "Write OpenSSH configuration to stdout", - Long: heredoc.Docf(` + Long: heredoc.Doc(` The config command generates per-codespace ssh configuration in OpenSSH format. Including this configuration in ~/.ssh/config improves the user experience of other @@ -433,9 +433,10 @@ func newConfigCmd(app *App) *cobra.Command { If -c/--codespace is specified, configuration is generated for that codespace only. Otherwise configuration is emitted for all available codespaces. - Codespaces that aren't in "Available" state are skipped because it's necessary to - connect to the running codespace to determine the required remote ssh username. - `, "`"), + When generating configuration for all codespaces, ones that aren't in "Available" + state are skipped because it's necessary to start the codespace to determine its + remote ssh username. When generating configuration for a single codespace with '-c', + `), Example: heredoc.Doc(` $ gh codespace config > ~/.ssh/codespaces $ echo 'include ~/.ssh/codespaces' >> ~/.ssh/config'