Move RemoteInfo and CloneProto to info package
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -102,13 +103,13 @@ func promptConfigSettings(c *config.Config) *config.Config {
|
||||
}
|
||||
|
||||
if proto, err := pterm.DefaultInteractiveSelect.
|
||||
WithOptions([]string{string(config.CloneProtoHTTP), string(config.CloneProtoSSH)}).
|
||||
WithOptions([]string{string(info.CloneProtoHTTP), string(info.CloneProtoSSH)}).
|
||||
WithDefaultText("Git Clone Protocol").
|
||||
Show(); err == nil {
|
||||
if proto == "ssh" {
|
||||
gitlabConfig.CloneProto = config.CloneProtoSSH
|
||||
gitlabConfig.CloneProto = info.CloneProtoSSH
|
||||
} else {
|
||||
gitlabConfig.CloneProto = config.CloneProtoHTTP
|
||||
gitlabConfig.CloneProto = info.CloneProtoHTTP
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ func init() {
|
||||
"Sets a path for local clones of projects")
|
||||
rootCmd.PersistentFlags().String("logLevel", defLogLevel,
|
||||
"Default log level -- info, warn, error, debug")
|
||||
rootCmd.PersistentFlags().StringSlice("remote", []string{},
|
||||
"Specify remotes by host for any sub-command. Provide multiple times or comma delimited.")
|
||||
|
||||
rootCmd.RegisterFlagCompletionFunc("logLevel", validLogLevelsFunc)
|
||||
|
||||
|
@ -27,6 +27,20 @@ func validProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete st
|
||||
return append(projectStrings, aliasStrings...), cobra.ShellCompDirectiveDefault
|
||||
}
|
||||
|
||||
func validRemotesFunc(cmd *cobra.Command, args []string, toComplete string) (
|
||||
[]string, cobra.ShellCompDirective) {
|
||||
var ttlRemotes int
|
||||
ttlRemotes += len(conf.Gitlabs)
|
||||
ttlRemotes += len(conf.Giteas)
|
||||
remotes := make([]string, 0, ttlRemotes)
|
||||
for _, remote := range conf.Gitlabs {
|
||||
if strings.HasPrefix(remote.Host, toComplete) {
|
||||
remotes = append(remotes, remote.Host)
|
||||
}
|
||||
}
|
||||
return remotes, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
func validGitlabRemotesFunc(cmd *cobra.Command, args []string, toComplete string) (
|
||||
[]string, cobra.ShellCompDirective) {
|
||||
remotes := make([]string, 0, len(conf.Gitlabs))
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
gitearemote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitea"
|
||||
gitlabremote "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@ -60,13 +61,14 @@ func getGiteaRemotes(cmd *cobra.Command) []remote.Remote {
|
||||
gitRemotes := make([]remote.Remote, 0)
|
||||
for _, gitea := range conf.Giteas {
|
||||
if gitea.CloneProto == "" {
|
||||
gitea.CloneProto = config.DefaultCloneProto
|
||||
gitea.CloneProto = info.DefaultCloneProto
|
||||
}
|
||||
giteaRemote, err := gitearemote.NewGiteaRemote(&remote.RemoteInfo{
|
||||
giteaRemote, err := gitearemote.NewGiteaRemote(&info.RemoteInfo{
|
||||
Ctx: cmd.Context(),
|
||||
Host: gitea.Host,
|
||||
Name: gitea.Name,
|
||||
Token: gitea.Token,
|
||||
Type: "gitea",
|
||||
CloneProto: gitea.CloneProto,
|
||||
})
|
||||
if err != nil {
|
||||
@ -89,20 +91,21 @@ func getGitLabRemotes(cmd *cobra.Command) []remote.Remote {
|
||||
Host: conf.GitlabHost,
|
||||
Name: conf.GitlabHost,
|
||||
Token: conf.GitlabToken,
|
||||
CloneProto: config.CloneProtoSSH,
|
||||
CloneProto: info.CloneProtoSSH,
|
||||
})
|
||||
}
|
||||
|
||||
// Load Gitlabs
|
||||
for _, gl := range conf.Gitlabs {
|
||||
if gl.CloneProto == "" {
|
||||
gl.CloneProto = config.DefaultCloneProto
|
||||
gl.CloneProto = info.DefaultCloneProto
|
||||
}
|
||||
gitlabRemote, err := gitlabremote.NewGitlabRemote(&remote.RemoteInfo{
|
||||
gitlabRemote, err := gitlabremote.NewGitlabRemote(&info.RemoteInfo{
|
||||
Ctx: cmd.Context(),
|
||||
Host: gl.Host,
|
||||
Name: gl.Name,
|
||||
Token: gl.Token,
|
||||
Type: "gitlab",
|
||||
CloneProto: gl.CloneProto,
|
||||
})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user