cli/cli

`gh cs` - Choose the only codespace if only one exists

alondahari opened this issue · 2 comments

Describe the feature or problem you’d like to solve

In the context of the gh cs subcommand, if I only have one active codespace it would be nice if it would be selected automatically. This is for any subcommand that requires choosing an existing codespace from a list, such as gh cs ssh.

I usually only have one codespace and I want to skip selecting it when I’m connecting.

Proposed solution

Potentially add it as a flag if we don't want to change the existing, skip the codespace selection step if only one exists and the command requires selecting an existing codespace.

This seems pretty trivial, and you could easily alias a workaround, but that would be a nice native behaviour imo. It could also help with scripting.

@alondahari : Thanks for opening this suggestion!

I could see this being a flag or even a configuration option you toggle, but I defer to our Codespaces team for consideration here.

cc: @dmgardiner25 @cmbrose

Thanks for the suggestion!

We actually started moving in this direction a while back when we refactored to the CodespaceSelecter helper. In there we have some logic that if you specify the repo name (-R/--repo) for (most) commands then we'll skip the prompt if there is only one codespace.

I think the reason that we stopped short of doing that in all cases was a bit of back compat in the experience and not being too magical. That said, I like the idea of an --auto-pick (hopefully we can find a better name 😅 ) flag which would force this behavior. That can easily be added to the CodespaceSelector flags.