Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Apr 7, 2025

This pull request proposes a new top-level preview command, enabling users and maintainers to easily preview or demo core elements of gh's UX. Currently, the only subcommand I'm proposing here is prompter to quickly run through all gh's prompting experiences in a no-op environment, but I could easily see this being useful with other features like:

  • gh preview color: print all the colors gh uses (think of a printer's test page 😁 )
  • gh preview progress: display whatever progress indicator you have configured for some time (either a textual one or a spinner)

This is related to #10710 because I had this idea while developing the accessible prompter changes.

Demo with accessible prompter

VHS tape file...


Set Width 1200
Set Height 600
Set Shell bash
Set TypingSpeed 40ms
Output out.gif
Env GH_EDITOR "vim"

# I put the env var here because I wanted to show the accessible prompter being used
# But you could easily set it with Env instead like I've done above for GH_EDITOR
Type "GH_ACCESSIBLE_PROMPTER=true ./bin/gh preview prompter"

# Select
Enter
Sleep 2s
Type "3"
Sleep 1.5s
Enter

# Multiselect
Sleep 2s
Type "3"
Sleep 1.5s
Enter
Sleep 1.5s
Type "1"
Sleep 1.5s
Enter
Sleep 1.5s
Type "2"
Sleep 1.5s
Enter
Type "0"
Sleep 1.5s
Enter

# Input
Sleep 2s
Type "Brunch"
Sleep 1.5s
Enter

# Password
Sleep 2s
Type "pineapple"
Sleep 1.5s
Enter

# Confirm
Sleep 2s
Type "n"
Sleep 1.5s
Enter

# Auth token
Sleep 2s
Type "ghp_1234567890"
Sleep 1.5s
Enter

# Delete confirmation
Sleep 2s
Type "delete-me"
Sleep 1.5s
Enter

# Hostname input
Sleep 2s
Type "github.com"
Sleep 1.5s
Enter

# Markdown editor with blanks allowed and default text
Sleep 2s
Type "2"
Sleep 1.5s
Enter

#  Markdown editor with blanks disallowed and default text
Sleep 2s
Type "1"
Sleep 1.5s
Enter
Sleep 1.5s
Type ":q!"
Sleep 1.5s
Enter

# Markdown editor with blanks disallowed and no default text
Sleep 2s
Type "1"
Sleep 1.5s
Enter
Sleep 1.5s
Type ":q!"
Sleep 1.5s
Enter
Sleep 3s

out

@BagToad BagToad force-pushed the kw/preview-prompter-command branch from b4e6d61 to abd573a Compare April 8, 2025 21:14
@BagToad BagToad force-pushed the kw/first-pass-accessible-prompter branch from d7de8fb to 4615069 Compare April 9, 2025 21:51
Base automatically changed from kw/first-pass-accessible-prompter to trunk April 10, 2025 23:28
@BagToad BagToad marked this pull request as ready for review April 16, 2025 22:07
Copilot AI review requested due to automatic review settings April 16, 2025 22:07
@BagToad BagToad requested a review from a team as a code owner April 16, 2025 22:07
@BagToad BagToad requested a review from babakks April 16, 2025 22:07
@BagToad BagToad temporarily deployed to cli-automation April 16, 2025 22:08 — with GitHub Actions Inactive
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new top-level "preview" command for demonstrating gh's prompting experiences in a no-op environment. Key changes include:

  • Adding a new "preview" command registration to the root command.
  • Implementing the "prompter" subcommand to demo various prompt types.
  • Creating a dedicated command file to integrate and manage preview commands.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
pkg/cmd/root/root.go Registers the preview command for UX demo purposes.
pkg/cmd/preview/prompter/prompter.go Implements interactive demos for different prompts.
pkg/cmd/preview/preview.go Sets up the preview command and integrates prompter.

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @BagToad! This really helps with trying different prompt types.

@babakks
Copy link
Member

babakks commented Apr 17, 2025

I'm wondering if in the future we may want to add more commands like this; I mean dev/meta/instrumentation kind of commands just for maintainers' debugging/diagnostic purposes. In that case, I'd rather see all of them under a single top-level command (e.g., debug, dev, or even _debug to avoid collision with potential thrid-party extensions).

What do you think?

@BagToad
Copy link
Member Author

BagToad commented Apr 22, 2025

I'm wondering if in the future we may want to add more commands like this; I mean dev/meta/instrumentation kind of commands just for maintainers' debugging/diagnostic purposes.

What do you think?

I agree, I had commented on this in the original PR body:

Currently, the only subcommand I'm proposing here is prompter to quickly run through all gh's prompting experiences in a no-op environment, but I could easily see this being useful with other features like:

  • gh preview color: print all the colors gh uses (think of a printer's test page 😁 )
  • gh preview progress: display whatever progress indicator you have configured for some time (either a textual one or a spinner)

In that case, I'd rather see all of them under a single top-level command (e.g., debug, dev, or even _debug to avoid collision with potential thrid-party extensions).

It is all currently proposed under a top level preview command already; are you alluding to a potential collision with preview?

I think that is a legitimate concern, but doesn't seem to collide with any public extensions currently 🤔 The extensions out there are close enough to preview that this gives me pause.

❯ gh ext search preview
Showing 3 of 3 extensions

  REPO                          DESCRIPTION                                                                                        
  yusukebe/gh-markdown-preview  GitHub CLI extension to preview Markdown looks like GitHub.
  thiagokokada/gh-gfm-preview   A standalone/GitHub CLI extension to preview GitHub Flavored Markdown, even offline.
  helibom/gh-starred            A GitHub CLI extension that fuzzy searches, previews and browses your starred repositories & lists.

I think _debug might be the least chance of colliding with an extension, but I think preview sounds better 😜

@andyfeller what do you think?

cmd.AddCommand(statusCmd.NewCmdStatus(f, nil))
cmd.AddCommand(codespaceCmd.NewCmdCodespace(f))
cmd.AddCommand(projectCmd.NewCmdProject(f))
cmd.AddCommand(previewCmd.NewCmdPreview(f))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Should there be a separate section for previews that shows each of the commands within?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I follow; are you talking about adding some whitespace here to separate cmd.AddCommand(previewCmd.NewCmdPreview(f)) from other commands?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion and the delay; let me elaborate.

Within the root command, the command groups created are turned into separate sections of the gh --help output:

cli/pkg/cmd/root/root.go

Lines 111 to 122 in 7ceca45

cmd.AddGroup(&cobra.Group{
ID: "core",
Title: "Core commands",
})
cmd.AddGroup(&cobra.Group{
ID: "actions",
Title: "GitHub Actions commands",
})
cmd.AddGroup(&cobra.Group{
ID: "extension",
Title: "Extension commands",
})

Expand for gh --help example

$ gh --help
Work seamlessly with GitHub from the command line.

USAGE
  gh <command> <subcommand> [flags]

CORE COMMANDS
  auth:          Authenticate gh and git with GitHub
  browse:        Open repositories, issues, pull requests, and more in the browser
  codespace:     Connect to and manage codespaces
  gist:          Manage gists
  issue:         Manage issues
  org:           Manage organizations
  pr:            Manage pull requests
  project:       Work with GitHub Projects.
  release:       Manage releases
  repo:          Manage repositories

GITHUB ACTIONS COMMANDS
  cache:         Manage GitHub Actions caches
  run:           View details about workflow runs
  workflow:      View details about GitHub Actions workflows

EXTENSION COMMANDS
  XXXXXXX:       Extension xxxx
  XXXXXXXXXX:    Extension xxxx
  ...

ALIAS COMMANDS
  xxxxxx:        Alias for "xxx"
  ...

ADDITIONAL COMMANDS
  alias:         Create command shortcuts
  api:           Make an authenticated GitHub API request
  attestation:   Work with artifact attestations
  completion:    Generate shell completion scripts
  config:        Manage configuration for gh
  extension:     Manage gh extensions
  gpg-key:       Manage GPG keys
  label:         Manage labels
  ruleset:       View info about repo rulesets
  search:        Search for repositories, issues, and pull requests
  secret:        Manage GitHub secrets
  ssh-key:       Manage SSH keys
  status:        Print information about relevant issues, pull requests, and notifications across repositories
  variable:      Manage GitHub Actions variables

This is handled deep in the bowels of gh:

cli/pkg/cmd/root/help.go

Lines 136 to 151 in 7ceca45

// Statically calculated padding for non-extension commands,
// longest is `gh accessibility` with 13 characters + 1 space.
//
// Should consider novel way to calculate this in the future [AF]
namePadding := 14
for _, g := range GroupedCommands(command) {
var names []string
for _, c := range g.Commands {
names = append(names, rpad(c.Name()+":", namePadding)+c.Short)
}
helpEntries = append(helpEntries, helpEntry{
Title: strings.ToUpper(g.Title),
Body: strings.Join(names, "\n"),
})
}

So, the suggestion was whether we should have a separate command group for preview commands or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PREVIEW COMMANDS
  prompter:         Execute a test program to preview the prompter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point actually. I like the separate group.

Copy link
Member Author

@BagToad BagToad May 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I got to implementing this and realized all the commands in gh --help are top level commands.

Like gh run and gh workflow, for example.

But in this case, only preview is our top-level command.

Referring back to the suggested output:

PREVIEW COMMANDS
  prompter:         Execute a test program to preview the prompter

Is this confusing that, for only the preview command group, none of the commands listed under the group are top-level commands? Are users going to understand that you have to run gh preview prompter and not gh prompter?

WDYT?

Maybe we can merge this PR without this, and then decide later how we'd want that to look?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😶 😬

PREVIEW COMMANDS
  preview prompter:         Execute a test program to preview the prompter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a fair point about users potentially being confused / missing these commands need to be gh preview.

I agree we should move forward with this PR as-is and revisit as we see how preview experiment proceeds.

Currently, preview will show up under ADDITIONAL COMMANDS section:

$ bin/gh help
Work seamlessly with GitHub from the command line.

USAGE
  gh <command> <subcommand> [flags]

CORE COMMANDS
  ...

GITHUB ACTIONS COMMANDS
  ...

EXTENSION COMMANDS
  ...

ALIAS COMMANDS
  ...

ADDITIONAL COMMANDS
  ...
  preview:       Execute previews for gh features

@BagToad BagToad requested a review from andyfeller May 10, 2025 17:55
@BagToad BagToad merged commit a04dc73 into trunk May 20, 2025
16 checks passed
@BagToad BagToad deleted the kw/preview-prompter-command branch May 20, 2025 19:13
@nata9014

This comment was marked as spam.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jun 13, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.73.0` -> `v2.74.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.74.1`](https://github.com/cli/cli/releases/tag/v2.74.1): GitHub CLI 2.74.1

[Compare Source](cli/cli@v2.74.0...v2.74.1)

#### What's Changed

-   Document support for `@copilot` in `gh [pr|issue] edit --add-assignee` and `--remove-assignee` by [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#11056
-   Fix pr edit when URL is provided by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11057
-   Fix const in MR finder tests by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11091

**Full Changelog**: cli/cli@v2.74.0...v2.74.1

### [`v2.74.0`](https://github.com/cli/cli/releases/tag/v2.74.0): GitHub CLI 2.74.0

[Compare Source](cli/cli@v2.73.0...v2.74.0)

#### Security

A security vulnerability has been identified in a core `gh` dependency, `go-gh`, where an attacker-controlled GitHub Enterprise Server could result in executing arbitrary commands on a user's machine by replacing HTTP URLs provided by GitHub with local file paths for browsing.

This issue is addressed in this `gh` release by updating `go-gh` to a fixed version.

For more information, see GHSA-g9f5-x53j-h563

#### What's changed

##### ✨ Features

-   Add `preview prompter` command by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10745
-   \[gh run watch] Support `--compact` flag by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10629
-   Fix brew update notifications by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11024

##### 🐛 Fixes

-   Revert "\[gh config] Escape pipe symbol in Long desc for website manual" by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11004
-   Fix formatting in allowed values for `gh config --help` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11003
-   fix: `gh gist edit` panic when no file in a gist by [@&#8203;phanen](https://github.com/phanen) in cli/cli#10627
-   Add retry logic when fetching TUF content in `gh attestation` commands by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10943

##### 📚 Docs & Chores

-   Update README.md by [@&#8203;irhdab](https://github.com/irhdab) in cli/cli#11022
-   Add tests for `RenderJobs` and `RenderJobsCompact` by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11013
-   Add example usage of `--head` option to `pr list` docs by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10979
-   Mention `pr create` will print the created MR's URL by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10980
-   Add Digest to ReleaseAsset struct by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#11030

##### :dependabot: Dependencies

-   Bump `go-gh` to v2.12.1 by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11043
-   chore(deps): bump github.com/gabriel-vasile/mimetype from 1.4.8 to 1.4.9 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10825
-   Update sigstore-go dependency to v1.0.0 by [@&#8203;malancas](https://github.com/malancas) in cli/cli#11028
-   chore(deps): bump github.com/sigstore/protobuf-specs from 0.4.1 to 0.4.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10999
-   chore(deps): bump github.com/yuin/goldmark from 1.7.8 to 1.7.12 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11032

#### New Contributors

-   [@&#8203;irhdab](https://github.com/irhdab) made their first contribution in cli/cli#11022
-   [@&#8203;phanen](https://github.com/phanen) made their first contribution in cli/cli#10627

**Full Changelog**: cli/cli@v2.73.0...v2.74.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC41MC4wIiwidXBkYXRlZEluVmVyIjoiNDAuNTAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants