Pass logger and config through CLI context (closes #725)

This commit is contained in:
Christopher Goes
2018-04-05 11:20:05 +02:00
parent 2ee3ca3192
commit 74a2246b3e
12 changed files with 158 additions and 88 deletions
+10 -14
View File
@@ -27,10 +27,10 @@ type appCreator func(string, log.Logger) (abci.Application, error)
// StartCmd runs the service passed in, either
// stand-alone, or in-process with tendermint
func StartCmd(app appCreator, logger log.Logger) *cobra.Command {
func StartCmd(app appCreator, ctx *Context) *cobra.Command {
start := startCmd{
appCreator: app,
logger: logger,
context: ctx,
}
cmd := &cobra.Command{
Use: "start",
@@ -49,15 +49,15 @@ func StartCmd(app appCreator, logger log.Logger) *cobra.Command {
type startCmd struct {
appCreator appCreator
logger log.Logger
context *Context
}
func (s startCmd) run(cmd *cobra.Command, args []string) error {
if !viper.GetBool(flagWithTendermint) {
s.logger.Info("Starting ABCI without Tendermint")
s.context.Logger.Info("Starting ABCI without Tendermint")
return s.startStandAlone()
}
s.logger.Info("Starting ABCI with Tendermint")
s.context.Logger.Info("Starting ABCI with Tendermint")
return s.startInProcess()
}
@@ -65,7 +65,7 @@ func (s startCmd) startStandAlone() error {
// Generate the app in the proper dir
addr := viper.GetString(flagAddress)
home := viper.GetString("home")
app, err := s.appCreator(home, s.logger)
app, err := s.appCreator(home, s.context.Logger)
if err != nil {
return err
}
@@ -74,7 +74,7 @@ func (s startCmd) startStandAlone() error {
if err != nil {
return errors.Errorf("Error creating listener: %v\n", err)
}
svr.SetLogger(s.logger.With("module", "abci-server"))
svr.SetLogger(s.context.Logger.With("module", "abci-server"))
svr.Start()
// Wait forever
@@ -86,13 +86,9 @@ func (s startCmd) startStandAlone() error {
}
func (s startCmd) startInProcess() error {
cfg, err := tcmd.ParseConfig()
if err != nil {
return err
}
cfg := s.context.Config
home := cfg.RootDir
app, err := s.appCreator(home, s.logger)
app, err := s.appCreator(home, s.context.Logger)
if err != nil {
return err
}
@@ -103,7 +99,7 @@ func (s startCmd) startInProcess() error {
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,
s.logger.With("module", "node"))
s.context.Logger.With("module", "node"))
if err != nil {
return err
}