Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command aliases to gh reference #8677

Closed
andyfeller opened this issue Feb 8, 2024 · 0 comments · Fixed by #8824
Closed

Add command aliases to gh reference #8677

andyfeller opened this issue Feb 8, 2024 · 0 comments · Fixed by #8824
Labels
enhancement a request to improve CLI gh-reference

Comments

@andyfeller
Copy link
Contributor

andyfeller commented Feb 8, 2024

In #8367, support for outputting aliases in help usage was added. One aspect that was discussed but not done was adding these aliases to gh reference output, which is a complete list of all commands within gh.

Originally posted by @andyfeller in #8367 comment

@Rebeccasun31 : What are your thoughts about enhancing gh reference to also include native aliases?

func stringifyReference(cmd *cobra.Command) string {
buf := bytes.NewBufferString("# gh reference\n\n")
for _, c := range cmd.Commands() {
if c.Hidden {
continue
}
cmdRef(buf, c, 2)
}
return buf.String()
}
func cmdRef(w io.Writer, cmd *cobra.Command, depth int) {
// Name + Description
fmt.Fprintf(w, "%s `%s`\n\n", strings.Repeat("#", depth), cmd.UseLine())
fmt.Fprintf(w, "%s\n\n", cmd.Short)
// Flags
// TODO: fold in InheritedFlags/PersistentFlags, but omit `--help` due to repetitiveness
if flagUsages := cmd.Flags().FlagUsages(); flagUsages != "" {
fmt.Fprintf(w, "```\n%s````\n\n", dedent(flagUsages))
}
// Subcommands
for _, c := range cmd.Commands() {
if c.Hidden {
continue
}
cmdRef(w, c, depth+1)
}
}

In general, I like @samcoe suggestion but realize it might be a little tricky because gh reference is alphabetized based on the command or subcommand name including user-created aliases. For example, gh codespace with an alias of cs would need an entry after several commands including gh codespace <subcommand>, gh completion, and gh config before an entry should show up. 🤔

## `gh codespace`

Connect to and manage codespaces

### `gh codespace code [flags]`

Open a codespace in Visual Studio Code

  -c, --codespace string    Name of the codespace
      --insiders            Use the insiders version of Visual Studio Code
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
  -w, --web                 Use the web version of Visual Studio Code

### `gh codespace cp [-e] [-r] [-- [<scp flags>...]] <sources>... <dest>`

Copy files between local and remote file systems

  -c, --codespace string    Name of the codespace
  -e, --expand              Expand remote file names on remote shell
  -p, --profile string      Name of the SSH profile to use
  -r, --recursive           Recursively copy directories
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)

### `gh codespace create [flags]`

Create a codespace

  -b, --branch string               repository branch
      --default-permissions         do not prompt to accept additional permissions requested by the codespace
      --devcontainer-path string    path to the devcontainer.json file to use when creating codespace
  -d, --display-name string         display name for the codespace
      --idle-timeout duration       allowed inactivity before codespace is stopped, e.g. "10m", "1h"
  -l, --location string             location: {EastUs|SouthEastAsia|WestEurope|WestUs2} (determined automatically if not provided)
  -m, --machine string              hardware specifications for the VM
  -R, --repo string                 repository name with owner: user/repo
      --retention-period duration   allowed time after shutting down before the codespace is automatically deleted (maximum 30 days), e.g. "1h", "72h"
  -s, --status                      show status of post-create command and dotfiles
  -w, --web                         create codespace from browser, cannot be used with --display-name, --idle-timeout, or --retention-period

### `gh codespace delete [flags]`

Delete codespaces

      --all                 Delete all codespaces
  -c, --codespace string    Name of the codespace
      --days N              Delete codespaces older than N days
  -f, --force               Skip confirmation for codespaces that contain unsaved changes
  -o, --org login           The login handle of the organization (admin-only)
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
  -u, --user username       The username to delete codespaces for (used with --org)

### `gh codespace edit [flags]`

Edit a codespace

  -c, --codespace string      Name of the codespace
  -d, --display-name string   Set the display name
  -m, --machine string        Set hardware specifications for the VM
  -R, --repo string           Filter codespace selection by repository name (user/repo)
      --repo-owner string     Filter codespace selection by repository owner (username or org)

### `gh codespace jupyter [flags]`

Open a codespace in JupyterLab

  -c, --codespace string    Name of the codespace
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)

### `gh codespace list [flags]`

List codespaces

  -q, --jq expression     Filter JSON output using a jq expression
      --json fields       Output JSON with the specified fields
  -L, --limit int         Maximum number of codespaces to list (default 30)
  -o, --org login         The login handle of the organization to list codespaces for (admin-only)
  -R, --repo string       Repository name with owner: user/repo
  -t, --template string   Format JSON output using a Go template; see "gh help formatting"
  -u, --user username     The username to list codespaces for (used with --org)
  -w, --web               List codespaces in the web browser, cannot be used with --user or --org

### `gh codespace logs [flags]`

Access codespace logs

  -c, --codespace string    Name of the codespace
  -f, --follow              Tail and follow the logs
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)

### `gh codespace ports [flags]`

List ports in a codespace

  -c, --codespace string    Name of the codespace
  -q, --jq expression       Filter JSON output using a jq expression
      --json fields         Output JSON with the specified fields
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
  -t, --template string     Format JSON output using a Go template; see "gh help formatting"

#### `gh codespace ports forward <remote-port>:<local-port>...`

Forward ports

#### `gh codespace ports visibility <port>:{public|private|org}...`

Change the visibility of the forwarded port

### `gh codespace rebuild [flags]`

Rebuild a codespace

  -c, --codespace string    Name of the codespace
      --full                perform a full rebuild
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)

### `gh codespace ssh [<flags>...] [-- <ssh-flags>...] [<command>]`

SSH into a codespace

  -c, --codespace string    Name of the codespace
      --config              Write OpenSSH configuration to stdout
  -d, --debug               Log debug data to a file
      --debug-file string   Path of the file log to
      --profile string      Name of the SSH profile to use
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
      --server-port int     SSH server port number (0 => pick unused)

### `gh codespace stop [flags]`

Stop a running codespace

  -c, --codespace string    Name of the codespace
  -o, --org login           The login handle of the organization (admin-only)
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
  -u, --user username       The username to stop codespace for (used with --org)

### `gh codespace view [flags]`

View details about a codespace

  -c, --codespace string    Name of the codespace
  -q, --jq expression       Filter JSON output using a jq expression
      --json fields         Output JSON with the specified fields
  -R, --repo string         Filter codespace selection by repository name (user/repo)
      --repo-owner string   Filter codespace selection by repository owner (username or org)
  -t, --template string     Format JSON output using a Go template; see "gh help formatting"

The only other thing that comes to mind is we don't create an entry but include the information in the main command description before it goes onto subcommands:

## `gh codespace`

Connect to and manage codespaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to improve CLI gh-reference
Projects
None yet
2 participants