RegisterBranchCompletionFlags suggests and autocompletes known remote git branches for flags passed
(gitc gitClient, cmd *cobra.Command, flags ...string)
| 51 | |
| 52 | // RegisterBranchCompletionFlags suggests and autocompletes known remote git branches for flags passed |
| 53 | func RegisterBranchCompletionFlags(gitc gitClient, cmd *cobra.Command, flags ...string) error { |
| 54 | for _, flag := range flags { |
| 55 | err := cmd.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 56 | if repoFlag := cmd.Flag("repo"); repoFlag != nil && repoFlag.Changed { |
| 57 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 58 | } |
| 59 | return gitc.TrackingBranchNames(context.TODO(), toComplete), cobra.ShellCompDirectiveNoFileComp |
| 60 | }) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | } |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func formatValuesForUsageDocs(values []string) string { |
| 69 | return fmt.Sprintf("{%s}", strings.Join(values, "|")) |
no test coverage detected