Package subcommand code

This commit is contained in:
2024-12-30 15:50:31 -05:00
parent 96378d047e
commit b9d7d5a4f2
51 changed files with 357 additions and 295 deletions

View File

@ -8,31 +8,34 @@ import (
"golang.org/x/exp/slices"
)
func (u *Utils) ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) (
func ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
u := MustFromCtx(cmd.Context())
u.InitProjectCache(cmd, args)
return u.Cache().ProjectStrings(toComplete), cobra.ShellCompDirectiveNoFileComp
}
func (u *Utils) ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
func ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
u.InitProjectCache(cmd, args)
return u.Cache().AliasStrings(toComplete), cobra.ShellCompDirectiveNoFileComp
utils := MustFromCtx(cmd.Context())
utils.InitProjectCache(cmd, args)
return utils.Cache().AliasStrings(toComplete), cobra.ShellCompDirectiveNoFileComp
}
func (u *Utils) ValidProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
projectStrings, _ := u.ValidAliasesFunc(cmd, args, toComplete)
aliasStrings, _ := u.ValidProjectsFunc(cmd, args, toComplete)
projectStrings, _ := ValidAliasesFunc(cmd, args, toComplete)
aliasStrings, _ := ValidProjectsFunc(cmd, args, toComplete)
return append(projectStrings, aliasStrings...), cobra.ShellCompDirectiveDefault
}
func (u *Utils) ValidRemotesFunc(_ *cobra.Command, _ []string, toComplete string) (
func ValidRemotesFunc(cmd *cobra.Command, _ []string, toComplete string) (
[]string, cobra.ShellCompDirective,
) {
u := MustFromCtx(cmd.Context())
remotes := make([]string, 0, len(u.Config().Remotes))
for _, remote := range u.Config().Remotes {
if strings.HasPrefix(remote.Host, toComplete) {