Move from --gitlab flags to global --remote flags
This commit is contained in:
17
cmd/root.go
17
cmd/root.go
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
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"
|
||||
)
|
||||
|
||||
var conf config.Config
|
||||
@@ -47,6 +49,7 @@ func init() {
|
||||
cobra.EnableTraverseRunHooks = true
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
// Global flags
|
||||
rootCmd.PersistentFlags().String("config", "",
|
||||
"config file (default is "+defConfigPath+")")
|
||||
rootCmd.PersistentFlags().String("projectPath", "",
|
||||
@@ -56,7 +59,9 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringSlice("remote", []string{},
|
||||
"Specify remotes by host for any sub-command. Provide multiple times or comma delimited.")
|
||||
|
||||
// Flag autocompletion
|
||||
rootCmd.RegisterFlagCompletionFunc("logLevel", validLogLevelsFunc)
|
||||
rootCmd.RegisterFlagCompletionFunc("remote", validRemotesFunc)
|
||||
|
||||
viper.BindPFlags(rootCmd.PersistentFlags())
|
||||
}
|
||||
@@ -106,6 +111,7 @@ func initConfig() {
|
||||
}
|
||||
|
||||
checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config
|
||||
setConfigFields() // Final chance to update config struct
|
||||
|
||||
plog.Debug("Configuration loaded", plog.Args("conf", conf))
|
||||
}
|
||||
@@ -127,6 +133,17 @@ func getPtermLogLevel(level string) pterm.LogLevel {
|
||||
return pLevel
|
||||
}
|
||||
|
||||
// Do any post-processing of configuration here
|
||||
func setConfigFields() {
|
||||
// Load Gitlabs
|
||||
glRemotes := gitlabremote.GitlabRemote{}
|
||||
conf.Remotes = append(conf.Remotes, glRemotes.GetInfos(conf)...)
|
||||
|
||||
// Load Giteas
|
||||
giteaRemotes := gitearemote.GiteaRemote{}
|
||||
conf.Remotes = append(conf.Remotes, giteaRemotes.GetInfos(conf)...)
|
||||
}
|
||||
|
||||
// Don't allow world-readable configuration
|
||||
func checkConfigPerms(file string) {
|
||||
stat, err := os.Stat(file)
|
||||
|
||||
Reference in New Issue
Block a user