Skip to content

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

Merged
mislav merged 10 commits into
trunkfrom
cobra-update
Dec 21, 2022
Merged

mislav merged 10 commits into
trunkfrom
cobra-update

Conversation

@mislav

@mislav mislav commented Nov 9, 2022 •

Copy link
Copy Markdown
Contributor

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
@chmouel

chmouel commented Nov 29, 2022 •

Copy link
Copy Markdown

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

mislav commented Nov 30, 2022 •

Copy link
Copy Markdown
Contributor Author

@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.

@samcoe samcoe left a comment

Copy link
Copy Markdown
Contributor

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.

@vilmibm vilmibm left a comment

Copy link
Copy Markdown
Contributor

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 enabled auto-merge December 21, 2022 13:50
@mislav
mislav merged commit c5ce685 into trunk Dec 21, 2022
@mislav
mislav deleted the cobra-update branch December 21, 2022 13:59
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.

[dependency] Upgrade spf13/cobra to atleast 1.6.0

5 participants