chore: fix completions by moving version info to root (#21903)

This commit is contained in:
andig 2025-06-18 14:43:29 +02:00 • committed by GitHub
parent c5596faaf6
commit 9ea2b050b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,6 +60,12 @@ var rootCmd = &cobra.Command{
func init() {
viper = vpr.NewWithOptions(vpr.ExperimentalBindStruct())
viper.SetEnvPrefix("evcc")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match
util.LogLevel("info", nil)
cobra.OnInitialize(initConfig)
// global options
@ -105,14 +111,6 @@ func initConfig() {
if cfgDatabase != "" {
viper.Set("Database.Dsn", cfgDatabase)
}
viper.SetEnvPrefix("evcc")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match
// print version
util.LogLevel("info", nil)
log.INFO.Printf("evcc %s", util.FormattedVersion())
}
// Execute adds all child commands to the root command and sets flags appropriately.
@ -126,6 +124,9 @@ func Execute() {
func runRoot(cmd *cobra.Command, args []string) {
runAsService = true
// print version
log.INFO.Printf("evcc %s", util.FormattedVersion())
// load config and re-configure logging after reading config file
var err error
if cfgErr := loadConfigFile(&conf, !cmd.Flag(flagIgnoreDatabase).Changed); errors.As(cfgErr, &vpr.ConfigFileNotFoundError{}) {