diff --git a/cmd/akash/cmd/root.go b/cmd/akash/cmd/root.go index b214557850..7e6138d944 100644 --- a/cmd/akash/cmd/root.go +++ b/cmd/akash/cmd/root.go @@ -103,6 +103,28 @@ func Execute(rootCmd *cobra.Command, envPrefix string) error { return executor.ExecuteContext(ctx) } +// Execute executes the root command. +func ExecuteWithCtx(ctx context.Context, rootCmd *cobra.Command, envPrefix string) error { + // Create and set a client.Context on the command's Context. During the pre-run + // of the root command, a default initialized client.Context is provided to + // seed child command execution with values such as AccountRetriver, Keyring, + // and a Tendermint RPC. This requires the use of a pointer reference when + // getting and setting the client.Context. Ideally, we utilize + // https://github.com/spf13/cobra/pull/1118. + srvCtx := sdkserver.NewDefaultContext() + + ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) + ctx = context.WithValue(ctx, sdkserver.ServerContextKey, srvCtx) + + rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)") + rootCmd.PersistentFlags().String(flags.FlagLogFormat, tmcfg.LogFormatPlain, "The logging format (json|plain)") + rootCmd.PersistentFlags().Bool(utilcli.FlagLogColor, false, "Pretty logging output. Applied only when log_format=plain") + rootCmd.PersistentFlags().String(utilcli.FlagLogTimestamp, "", "Add timestamp prefix to the logs (rfc3339|rfc3339nano|kitchen)") + + executor := tmcli.PrepareBaseCmd(rootCmd, envPrefix, app.DefaultHome) + return executor.ExecuteContext(ctx) +} + func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { debugCmd := debug.Cmd() debugCmd.AddCommand(ConvertBech32Cmd())