Skip to content

gh cs commands accept a -r flag to filter to a specific repo #6548

Description

@cmbrose

For gh cs commands which show a codespace selection prompt (code, ssh, ports, etc), we can accept an optional -r parameter to specify a repo. This parameter can be used to pre-filter the list of codespaces and in the case that only a single codespace matches, auto-select it.

In terms of implementation, most/all of these commands go through getOrChooseCodespace, so adding the parameter there should allow all of these commands to get the same functionality at once.

For example:

Without -r

$ gh cs code
? Choose codespace:  [Use arrows to move, type to filter]
> cli/cli (trunk): didactic parakeet
  cli/cli (trunk): fictional fiesta
  devcontainer/features (main): humble train

Multiple matches with -r

$ gh cs code -r cli/cli
? Choose codespace:  [Use arrows to move, type to filter]
> cli/cli (trunk): didactic parakeet
  cli/cli (trunk): fictional fiesta

Multiple matches with -r

$ gh cs code -r devcontainer/features
(vscode immediately opens "humble train")

No matches with -r

$ gh cs code -r foo/bar
Error: no codespaces exist for the specified repository

Activity

  1. jungaretti commented on Nov 1, 2022

    @jungaretti
    Contributor

    This makes sense to me!

  2. added
    enhancementa request to improve CLI
    and removed on Nov 7, 2022
  3. mislav commented on Nov 7, 2022

    @mislav
    Contributor

    We (the CLI core team) have discussed this and the proposal looks good!

    Note that one codespace command cs cp already has an unrelated -r flag.

  4. cmbrose commented on Nov 7, 2022

    @cmbrose
    MemberAuthor

    Thanks for catching that in cs cp @mislav!

    Do you/the team have any recommendations to handling that? I think it would be:

    1. Only have --repo for cs cp (which makes it slightly different from all the other commands)
    2. Repurpose -r for cs cp and break anything currently using -r
      • Could switch --recursive to -R instead to keep the short flag
      • Could go with option 1 for now and mark -r as deprecated for some time?
    3. Start migrating codespaces commands to -R instead of -r to avoid the collision, mark existing -r as deprecated

    Option 1 is basically long term pain to avoid short term hassle - option 2 is the opposite.
    My inclination is option 2, but would love feedback for how to reduce pain from breakage and generally how the CLI prefers to handle that type of change.

    Option 3 is a good opportunity to align the codespaces commands with other commands on using -R and avoids breaking changes and special casing entirely. Leaving the -r options to be deprecated would impact the create, delete, and list.

  5. rneatherway commented on Dec 12, 2022

    @rneatherway
    Contributor

    Drive-by comment, please feel free to ignore.

    Most of the other commands seem to use a shared option:

    -R, --repo [HOST/]OWNER/REPO   Select another repository using the [HOST/]OWNER/REPO format
    

    Another option would be to use -R for consistency with the rest of the CLI and support -r as a deprecated backwards-compatible option for e.g. cs create which already has -r as a synonym for --repo.

  6. jungaretti commented on Dec 12, 2022

    @jungaretti
    Contributor

    All of the gh cs commands use -r instead of -R, but I agree that this is somewhat confusing. Switching to -R and supporting -r for backwards compatibility sounds like a good idea to me!

  7. cmbrose commented on Dec 12, 2022

    @cmbrose
    MemberAuthor

    Actually I really like that suggestion @rneatherway - the discrepancy of -r/-R in the codespaces command set had bugged me for a while, but I hand't considered just getting two birds with one stone here 😄 I updated the list of options above with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions