remove config parsing block from root command

This commit is contained in:
A.Unger
2020-03-17 15:00:18 +01:00
parent e369509df3
commit e1405995be

View File

@@ -2,7 +2,6 @@ package command
import (
"os"
"strings"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis-pkg/v2/log"
@@ -11,7 +10,6 @@ import (
"github.com/owncloud/ocis/pkg/micro/runtime"
"github.com/owncloud/ocis/pkg/register"
"github.com/owncloud/ocis/pkg/version"
"github.com/spf13/viper"
)
// Execute is the entry point for the ocis-ocis command.
@@ -30,53 +28,9 @@ func Execute() error {
Email: "support@owncloud.com",
},
},
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
logger := NewLogger(cfg)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("OCIS")
viper.AutomaticEnv()
if c.IsSet("config-file") {
viper.SetConfigFile(c.String("config-file"))
} else {
viper.SetConfigName("ocis")
viper.AddConfigPath("/etc/ocis")
viper.AddConfigPath("$HOME/.ocis")
viper.AddConfigPath("./config")
}
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
logger.Info().
Msg("Continue without config")
case viper.UnsupportedConfigError:
logger.Fatal().
Err(err).
Msg("Unsupported config type")
default:
logger.Fatal().
Err(err).
Msg("Failed to read config")
}
}
if err := viper.Unmarshal(&cfg); err != nil {
logger.Fatal().
Err(err).
Msg("Failed to parse config")
}
return nil
},
}
// Load commands from the registry
for _, fn := range register.Commands {
app.Commands = append(
app.Commands,