remove config parsing block from root command
This commit is contained in:
@@ -2,7 +2,6 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/micro/cli/v2"
|
"github.com/micro/cli/v2"
|
||||||
"github.com/owncloud/ocis-pkg/v2/log"
|
"github.com/owncloud/ocis-pkg/v2/log"
|
||||||
@@ -11,7 +10,6 @@ import (
|
|||||||
"github.com/owncloud/ocis/pkg/micro/runtime"
|
"github.com/owncloud/ocis/pkg/micro/runtime"
|
||||||
"github.com/owncloud/ocis/pkg/register"
|
"github.com/owncloud/ocis/pkg/register"
|
||||||
"github.com/owncloud/ocis/pkg/version"
|
"github.com/owncloud/ocis/pkg/version"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Execute is the entry point for the ocis-ocis command.
|
// Execute is the entry point for the ocis-ocis command.
|
||||||
@@ -30,53 +28,9 @@ func Execute() error {
|
|||||||
Email: "support@owncloud.com",
|
Email: "support@owncloud.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Flags: flagset.RootWithConfig(cfg),
|
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 {
|
for _, fn := range register.Commands {
|
||||||
app.Commands = append(
|
app.Commands = append(
|
||||||
app.Commands,
|
app.Commands,
|
||||||
|
|||||||
Reference in New Issue
Block a user