Visitar URL original
Update Cobra and make use of its new command grouping by mislav · Pull Request #6589 · cli/cli · GitHub
The Wayback Machine - https://web.archive.org/web/20240519002959/https://github.com/cli/cli/pull/6589
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

Update Cobra and make use of its new command grouping #6589

Merged
merged 10 commits into from Dec 21, 2022
Merged

Conversation

mislav
Copy link
Contributor

@mislav mislav commented Nov 9, 2022 •

Cobra 1.6 supports command grouping natively.

CORE COMMANDS
  auth:        Authenticate gh and git with GitHub
  browse:      Open the repository in the browser
  codespace:   Connect to and manage codespaces
  ...

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

ADDITIONAL COMMANDS
  alias:       Create command shortcuts
  ...

Apart from grouping on the root command, arbitrary grouping is now supported at any level. As an experiment, this PR introduces grouping on the gh issue level:

GENERAL COMMANDS
  create:      Create a new issue
  list:        List issues in a repository
  status:      Show status of relevant issues

ADDITIONAL COMMANDS
  close:       Close issue
  comment:     Add a comment to an issue
  delete:      Delete issue
  ...

The idea is to group together "general" issue commands, i.e. those that do not operate on any specific issue, vs. those that need an issue argument. Although, I'm not still happy with group names. Any better suggestions?

Bonus for testing: since we completely override so many of Cobra's features, I thought it would be nice to be able to temporarily restore Cobra default behaviors for comparison, so this introduces the GH_COBRA environment variable for testing. When set, Cobra reverts to its out-of-the-box settings:

  • default help func for commands,
  • default command error handling,
  • default usage help,
  • built-in man page generation,
  • built-in markdown page generation.

Fixes #6523

Setting GH_COBRA allows access to Cobra's built-in implementation of generating man pages and markdown trees. This is useful for testing and comparing our overrides against Cobra's own logic.
@mislav mislav requested a review from a team as a code owner November 9, 2022 20:42
@mislav mislav requested review from samcoe and removed request for a team November 9, 2022 20:42
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Nov 9, 2022
@chmouel
Copy link

chmouel commented Nov 29, 2022 •

we may get away using handcrafted shell completion to get a better user experience,

I have experimented a bit with completion and gh, here is a wrapper around "gh issue create" to complete owner/repo with assignee bug and label coming from the owner/repo. (wrapper, and completion)

demo:

Screen.Recording.2022-11-29.at.08.42.22.mov

I don't think with cobra we could inject some context and completion depending of previous arguments..

@mislav
Copy link
Contributor Author

mislav commented Nov 30, 2022 •

@chmouel That demo looks really cool. We track improving completion support across gh in these separate issues: #360 #5576. If you want to submit a PR, you're very welcome!

Note that for now and for simplicity, we limit ourselves to only adding the styles of completion that Cobra itself supports.

Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

Code LGTM. I like the idea proposed offline of targeted vs general commands. Since that would require changing many more commands perhaps we should push that to another PR? Up to you though.

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Dec 5, 2022
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

discussed in sync

@mislav mislav merged commit c5ce685 into trunk Dec 21, 2022
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Dec 21, 2022
@mislav mislav deleted the cobra-update branch December 21, 2022 13:59
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

[dependency] Upgrade spf13/cobra to atleast 1.6.0
4 participants