Conversation
mislav
left a comment
There was a problem hiding this comment.
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 🦖 |
mislav
left a comment
There was a problem hiding this comment.
I have taken another pass at this and added --repo flag handling. Thanks!!
Co-authored-by: Mislav Marohnić <mislav@github.com>
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