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
Autocomplete branch flags #6031
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great so far!
- Note that some other commands also take in branch names via flags, for example
gh pr create; - Note that most commands take in a
-R/--repoflag or theGH_REPOenvironment variable to override which repository is the "current" one. In those cases, we don't want to be reading branch information from the local git repository because it will likely not match the repository the user has explicitly selected.
b6356b7
to
9474540
Compare
I would think a lot of use cases for I'm in my local git repository which has a base repo of If you don't think this is a frequent scenario, do you possibly have a suggestion as to how to prevent autocompletion on scenario # 2? _ = cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if cmd.Flag("repo").Changed {
return []string{"AUTOCOMPLETE NOT ALLOWED WITH REPO FLAG"}, cobra.ShellCompDirectiveDefault
}
return options, cobra.ShellCompDirectiveNoFileComp
})I tried this but I don't think the repo flag is set until the user runs the command. Would there be another approach you would take? Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have taken another pass at this and added --repo flag handling. Thanks!!
Looks like there might be others looking for this?
#2877, #2992
This happens to me often enough to make a pr:
$ gh pr create -B..."what version is this merging into again?"...^C*Proceeds to run a git branch just to type out the above again with a branch named "release/some-version"
Having an autocomplete on flags that accept a branch name helps me in two ways:
I didn't want to import the git package into
edit.go. I'm wondering if the branch resolver should live elsewhere?Ref: #360