Bug fixes, config generator
This commit is contained in:
24
cmd/root.go
24
cmd/root.go
@@ -38,7 +38,7 @@ func Execute() {
|
||||
err := rootCmd.ExecuteContext(ctx)
|
||||
|
||||
if err != nil {
|
||||
plog.Error("Failed to execute command", plog.Args("err", err))
|
||||
pterm.Error.Printfln(pterm.LightYellow("Command failed, " + err.Error()))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -48,12 +48,12 @@ func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
rootCmd.PersistentFlags().String("config", "",
|
||||
"config file (default is $HOME/.gitlab-project-manager.yaml)")
|
||||
"config file (default is "+defConfigPath+")")
|
||||
rootCmd.PersistentFlags().String("gitlabHost", defGitlabHost,
|
||||
"GitLab Hostname (e.g. gitlab.com)")
|
||||
rootCmd.PersistentFlags().String("gitlabToken", "",
|
||||
"GitLab Tokenname (e.g. gitlab.com)")
|
||||
rootCmd.PersistentFlags().String("projectPath", defProjectsPath,
|
||||
rootCmd.PersistentFlags().String("projectPath", "",
|
||||
"Sets a path for local clones of projects")
|
||||
rootCmd.PersistentFlags().String("logLevel", defLogLevel,
|
||||
"Default log level -- info, warn, error, debug")
|
||||
@@ -73,16 +73,14 @@ func initConfig() {
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Search config in home directory with name ".gitlab-project-manager" (without extension).
|
||||
viper.AddConfigPath(home)
|
||||
viper.AddConfigPath(home + "/.config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.SetConfigName(".gitlab-project-manager")
|
||||
viper.SetConfigName("gitlab-project-manager")
|
||||
}
|
||||
|
||||
viper.AutomaticEnv()
|
||||
viper.ReadInConfig()
|
||||
|
||||
checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config
|
||||
|
||||
// Configure pretty logger
|
||||
plog = pterm.DefaultLogger.
|
||||
WithLevel(getPtermLogLevel(viper.GetString("logLevel"))).
|
||||
@@ -97,6 +95,18 @@ func initConfig() {
|
||||
plog.Error("Failed loading config", plog.Args("err", err))
|
||||
}
|
||||
|
||||
if len(os.Args) > 0 && strings.HasPrefix(os.Args[1], "conf") {
|
||||
plog.Debug("Permitting missing config for config sub-command")
|
||||
return
|
||||
} else if conf.ProjectPath == "" {
|
||||
plog.Fatal("Minimal configuration missing, must have projectPath", plog.Args(
|
||||
"do",
|
||||
"Try running `gitlab-project-manager config default > "+defConfigPath,
|
||||
))
|
||||
}
|
||||
|
||||
checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config
|
||||
|
||||
plog.Debug("Configuration loaded", plog.Args("conf", conf))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user