refactor: remove cometbft/libs/cli import (#15673)
This commit is contained in:
parent
f69fdad424
commit
c1974e4b3c
@ -99,6 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (client) [#15673](https://github.com/cosmos/cosmos-sdk/pull/15673) Move `client/keys.OutputFormatJSON` and `client/keys.OutputFormatText` to `client/flags` package.
|
||||
* (x/nft) [#15588](https://github.com/cosmos/cosmos-sdk/pull/15588) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey` and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context`.
|
||||
* (x/auth) [#15520](https://github.com/cosmos/cosmos-sdk/pull/15520) `NewAccountKeeper` now takes a `KVStoreService` instead of a `StoreKey` and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context`.
|
||||
* (x/consensus) [#15517](https://github.com/cosmos/cosmos-sdk/pull/15517) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`.
|
||||
@ -144,11 +145,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (x/capability) [#15344](https://github.com/cosmos/cosmos-sdk/pull/15344) Capability module was removed and is now housed in [IBC-GO](https://github.com/cosmos/ibc-go).
|
||||
* [#15299](https://github.com/cosmos/cosmos-sdk/pull/15299) remove `StdTx` transaction and signing APIs. No SDK version has actually supported `StdTx` since before Stargate.
|
||||
* [#15600](https://github.com/cosmos/cosmos-sdk/pull/15600) add support for getting signers to `codec.Codec` and protoregistry support to `InterfaceRegistry`:
|
||||
* `Codec` is now a private interface and has the methods `InterfaceRegistry`, `GetMsgAnySigners`, `GetMsgV1Signers`, and `GetMsgV2Signers` which will fail when using `AminoCodec`.
|
||||
* `Codec` is now a private interface and has the methods `InterfaceRegistry`, `GetMsgAnySigners`, `GetMsgV1Signers`, and `GetMsgV2Signers` which will fail when using `AminoCodec`.
|
||||
All implementations of `Codec` by other users must now embed an official implementation from the `codec` package.
|
||||
* `InterfaceRegistry` is now a private interface and implements `protodesc.Resolver` plus the `RangeFiles` method
|
||||
* `InterfaceRegistry` is now a private interface and implements `protodesc.Resolver` plus the `RangeFiles` method
|
||||
All implementations of `InterfaceRegistry` by other users must now embed the official implementation.
|
||||
* `AminoCodec` is marked as deprecated.
|
||||
* `AminoCodec` is marked as deprecated.
|
||||
|
||||
### Client Breaking Changes
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"google.golang.org/grpc"
|
||||
@ -92,8 +91,8 @@ func ValidateCmd(cmd *cobra.Command, args []string) error {
|
||||
// - client.Context field pre-populated & flag not set: uses pre-populated value
|
||||
// - client.Context field pre-populated & flag set: uses set flag value
|
||||
func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error) {
|
||||
if clientCtx.OutputFormat == "" || flagSet.Changed(cli.OutputFlag) {
|
||||
output, _ := flagSet.GetString(cli.OutputFlag)
|
||||
if clientCtx.OutputFormat == "" || flagSet.Changed(flags.FlagOutput) {
|
||||
output, _ := flagSet.GetString(flags.FlagOutput)
|
||||
clientCtx = clientCtx.WithOutputFormat(output)
|
||||
}
|
||||
|
||||
@ -305,8 +304,8 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
|
||||
if isAux {
|
||||
// If the user didn't explicitly set an --output flag, use JSON by
|
||||
// default.
|
||||
if clientCtx.OutputFormat == "" || !flagSet.Changed(cli.OutputFlag) {
|
||||
clientCtx = clientCtx.WithOutputFormat("json")
|
||||
if clientCtx.OutputFormat == "" || !flagSet.Changed(flags.FlagOutput) {
|
||||
clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON)
|
||||
}
|
||||
|
||||
// If the user didn't explicitly set a --sign-mode flag, use
|
||||
|
||||
@ -20,11 +20,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
const (
|
||||
text = "text"
|
||||
jsonText = "json"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
viper.Set(flags.FlagKeyringBackend, keyring.BackendMemory)
|
||||
os.Exit(m.Run())
|
||||
@ -51,7 +46,7 @@ func TestContext_PrintProto(t *testing.T) {
|
||||
// json
|
||||
buf := &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = jsonText
|
||||
ctx.OutputFormat = flags.OutputFormatJSON
|
||||
err = ctx.PrintProto(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
@ -61,7 +56,7 @@ func TestContext_PrintProto(t *testing.T) {
|
||||
// yaml
|
||||
buf = &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = text
|
||||
ctx.OutputFormat = flags.OutputFormatText
|
||||
err = ctx.PrintProto(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
@ -94,7 +89,7 @@ func TestContext_PrintObjectLegacy(t *testing.T) {
|
||||
// json
|
||||
buf := &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = jsonText
|
||||
ctx.OutputFormat = flags.OutputFormatJSON
|
||||
err = ctx.PrintObjectLegacy(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
@ -104,7 +99,7 @@ func TestContext_PrintObjectLegacy(t *testing.T) {
|
||||
// yaml
|
||||
buf = &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = text
|
||||
ctx.OutputFormat = flags.OutputFormatText
|
||||
err = ctx.PrintObjectLegacy(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
@ -126,7 +121,7 @@ func TestContext_PrintRaw(t *testing.T) {
|
||||
// json
|
||||
buf := &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = jsonText
|
||||
ctx.OutputFormat = flags.OutputFormatJSON
|
||||
err := ctx.PrintRaw(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
@ -136,7 +131,7 @@ func TestContext_PrintRaw(t *testing.T) {
|
||||
// yaml
|
||||
buf = &bytes.Buffer{}
|
||||
ctx = ctx.WithOutput(buf)
|
||||
ctx.OutputFormat = text
|
||||
ctx.OutputFormat = flags.OutputFormatText
|
||||
err = ctx.PrintRaw(hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t,
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
cmtcli "github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
@ -45,7 +44,7 @@ const (
|
||||
|
||||
// List of CLI flags
|
||||
const (
|
||||
FlagHome = cmtcli.HomeFlag
|
||||
FlagHome = "home"
|
||||
FlagKeyringDir = "keyring-dir"
|
||||
FlagUseLedger = "ledger"
|
||||
FlagChainID = "chain-id"
|
||||
@ -86,13 +85,18 @@ const (
|
||||
FlagInitHeight = "initial-height"
|
||||
// FlagOutput is the flag to set the output format.
|
||||
// This differs from FlagOutputDocument that is used to set the output file.
|
||||
FlagOutput = cmtcli.OutputFlag
|
||||
|
||||
FlagOutput = "output"
|
||||
// Logging flags
|
||||
FlagLogLevel = "log_level"
|
||||
FlagLogFormat = "log_format"
|
||||
)
|
||||
|
||||
// List of supported output formats
|
||||
const (
|
||||
OutputFormatJSON = "json"
|
||||
OutputFormatText = "text"
|
||||
)
|
||||
|
||||
// LineBreak can be included in a command list to provide a blank line
|
||||
// to help with readability
|
||||
var LineBreak = &cobra.Command{Run: func(*cobra.Command, []string) {}}
|
||||
@ -113,7 +117,7 @@ func AddQueryFlagsToCmd(cmd *cobra.Command) {
|
||||
// AddTxFlagsToCmd adds common flags to a module tx command.
|
||||
func AddTxFlagsToCmd(cmd *cobra.Command) {
|
||||
f := cmd.Flags()
|
||||
f.StringP(FlagOutput, "o", "json", "Output format (text|json)")
|
||||
f.StringP(FlagOutput, "o", OutputFormatJSON, "Output format (text|json)")
|
||||
f.String(FlagFrom, "", "Name or address of private key with which to sign")
|
||||
f.Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)")
|
||||
f.Uint64P(FlagSequence, "s", 0, "The sequence number of the signing account (offline mode only)")
|
||||
|
||||
@ -302,7 +302,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
|
||||
func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemonic, outputFormat string) error {
|
||||
switch outputFormat {
|
||||
case OutputFormatText:
|
||||
case flags.OutputFormatText:
|
||||
cmd.PrintErrln()
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), k, MkAccKeyOutput, outputFormat); err != nil {
|
||||
return err
|
||||
@ -314,7 +314,7 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo
|
||||
return fmt.Errorf("failed to print mnemonic: %v", err)
|
||||
}
|
||||
}
|
||||
case OutputFormatJSON:
|
||||
case flags.OutputFormatJSON:
|
||||
out, err := MkAccKeyOutput(k)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -54,7 +53,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
fmt.Sprintf("--%s=0", flagAccount),
|
||||
fmt.Sprintf("--%s=0", flagIndex),
|
||||
fmt.Sprintf("--%s=330", flagCoinType),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
@ -104,7 +103,7 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
cmd.SetArgs([]string{
|
||||
"keyname1",
|
||||
fmt.Sprintf("--%s=true", flags.FlagUseLedger),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%d", flagCoinType, sdk.CoinType),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -43,7 +42,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
cmd.SetArgs([]string{
|
||||
"keyname1",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
@ -56,7 +55,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
cmd.SetArgs([]string{
|
||||
"keyname2",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
@ -70,7 +69,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
cmd.SetArgs([]string{
|
||||
"keyname4",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
||||
})
|
||||
@ -82,7 +81,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
"keyname5",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
||||
fmt.Sprintf("--%s=true", flags.FlagDryRun),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
})
|
||||
|
||||
@ -245,7 +244,7 @@ func TestAddRecoverFileBackend(t *testing.T) {
|
||||
cmd.SetArgs([]string{
|
||||
"keyname1",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
||||
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendFile),
|
||||
fmt.Sprintf("--%s", flagRecover),
|
||||
|
||||
@ -8,10 +8,10 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/bech32"
|
||||
)
|
||||
@ -98,7 +98,7 @@ func doParseKey(cmd *cobra.Command, config *sdk.Config, args []string) error {
|
||||
return errors.New("couldn't parse empty input")
|
||||
}
|
||||
|
||||
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
||||
output, _ := cmd.Flags().GetString(flags.FlagOutput)
|
||||
if !(runFromBech32(outstream, addr, output) || runFromHex(config, outstream, addr, output)) {
|
||||
return errors.New("couldn't find valid bech32 nor hex data")
|
||||
}
|
||||
@ -137,10 +137,10 @@ func displayParseKeyInfo(w io.Writer, stringer fmt.Stringer, output string) {
|
||||
)
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
case flags.OutputFormatText:
|
||||
out, err = yaml.Marshal(&stringer)
|
||||
|
||||
case OutputFormatJSON:
|
||||
case flags.OutputFormatJSON:
|
||||
out, err = json.Marshal(&stringer)
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
@ -52,7 +51,7 @@ The pass backend requires GnuPG: https://gnupg.org/
|
||||
)
|
||||
|
||||
cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
|
||||
cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)")
|
||||
cmd.PersistentFlags().String(flags.FlagOutput, "text", "Output format (text|json)")
|
||||
flags.AddKeyringFlags(cmd.PersistentFlags())
|
||||
|
||||
return cmd
|
||||
|
||||
@ -4,12 +4,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/ledger"
|
||||
@ -97,7 +97,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
isShowDevice, _ := cmd.Flags().GetBool(FlagDevice)
|
||||
|
||||
isOutputSet := false
|
||||
tmp := cmd.Flag(cli.OutputFlag)
|
||||
tmp := cmd.Flag(flags.FlagOutput)
|
||||
if tmp != nil {
|
||||
isOutputSet = tmp.Changed
|
||||
}
|
||||
@ -117,7 +117,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
if isOutputSet {
|
||||
clientCtx.OutputFormat, _ = cmd.Flags().GetString(cli.OutputFlag)
|
||||
clientCtx.OutputFormat, _ = cmd.Flags().GetString(flags.FlagOutput)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
@ -7,15 +7,10 @@ import (
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
cryptokeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
// available output formats.
|
||||
const (
|
||||
OutputFormatText = "text"
|
||||
OutputFormatJSON = "json"
|
||||
)
|
||||
|
||||
type bechKeyOutFn func(k *cryptokeyring.Record) (KeyOutput, error)
|
||||
|
||||
func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKeyOutFn, output string) error {
|
||||
@ -25,12 +20,12 @@ func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKey
|
||||
}
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
case flags.OutputFormatText:
|
||||
if err := printTextRecords(w, []KeyOutput{ko}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case OutputFormatJSON:
|
||||
case flags.OutputFormatJSON:
|
||||
out, err := json.Marshal(ko)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -51,12 +46,12 @@ func printKeyringRecords(w io.Writer, records []*cryptokeyring.Record, output st
|
||||
}
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
case flags.OutputFormatText:
|
||||
if err := printTextRecords(w, kos); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case OutputFormatJSON:
|
||||
case flags.OutputFormatJSON:
|
||||
out, err := json.Marshal(kos)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -3,7 +3,6 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
cmtcli "github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/spf13/cobra"
|
||||
@ -27,7 +26,8 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error {
|
||||
ctx := CreateExecuteContext(context.Background())
|
||||
|
||||
rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic)")
|
||||
rootCmd.PersistentFlags().String(flags.FlagLogFormat, cmtcfg.LogFormatPlain, "The logging format (json|plain)")
|
||||
// NOTE: The default logger is only checking for the "json" value, any other value will default to plain text.
|
||||
rootCmd.PersistentFlags().String(flags.FlagLogFormat, "plain", "The logging format (json|plain)")
|
||||
|
||||
executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome)
|
||||
return executor.ExecuteContext(ctx)
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
|
||||
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
cmtcli "github.com/cometbft/cometbft/libs/cli"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/spf13/cast"
|
||||
@ -170,7 +169,7 @@ func InterceptConfigsAndCreateContext(cmd *cobra.Command, customAppConfigTemplat
|
||||
// It reads the log level and format from the server context.
|
||||
func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) {
|
||||
var opts []log.Option
|
||||
if ctx.Viper.GetString(flags.FlagLogFormat) == cmtcfg.LogFormatJSON {
|
||||
if ctx.Viper.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON {
|
||||
opts = append(opts, log.OutputJSONOption())
|
||||
}
|
||||
|
||||
@ -181,7 +180,8 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) {
|
||||
}
|
||||
|
||||
logLvl, err := zerolog.ParseLevel(logLvlStr)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err != nil:
|
||||
// If the log level is not a valid zerolog level, then we try to parse it as a key filter.
|
||||
filterFunc, err := log.ParseLogLevel(logLvlStr)
|
||||
if err != nil {
|
||||
@ -190,11 +190,11 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) {
|
||||
|
||||
opts = append(opts, log.FilterOption(filterFunc))
|
||||
|
||||
} else if ctx.Viper.GetBool(cmtcli.TraceFlag) {
|
||||
case ctx.Viper.GetBool("trace"): // cmtcli.TraceFlag
|
||||
// Check if the CometBFT flag for trace logging is set if it is then setup a tracing logger in this app as well.
|
||||
// Note it overrides log level passed in `log_levels`.
|
||||
opts = append(opts, log.LevelOption(zerolog.TraceLevel))
|
||||
} else {
|
||||
default:
|
||||
opts = append(opts, log.LevelOption(logLvl))
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
cmtcli "github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -220,7 +219,7 @@ func (s *E2ETestSuite) TestCLISignGenOnly() {
|
||||
|
||||
for _, tc := range cases {
|
||||
cmd := authcli.GetSignCommand()
|
||||
cmtcli.PrepareBaseCmd(cmd, "", "")
|
||||
cmd.PersistentFlags().String(flags.FlagHome, val.ClientCtx.HomeDir, "directory for config and data")
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
|
||||
if tc.expErr {
|
||||
s.Require().Error(err)
|
||||
|
||||
@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cli2 "github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
)
|
||||
@ -37,7 +37,7 @@ func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraA
|
||||
}
|
||||
|
||||
func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{address.String(), fmt.Sprintf("--%s=json", cli2.OutputFlag)}
|
||||
args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)}
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(), args)
|
||||
|
||||
@ -5,12 +5,14 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
const flagLong = "long"
|
||||
const (
|
||||
flagLong = "long"
|
||||
flagOutput = "output"
|
||||
)
|
||||
|
||||
// NewVersionCommand returns a CLI command to interactively print the application binary version information.
|
||||
func NewVersionCommand() *cobra.Command {
|
||||
@ -31,7 +33,7 @@ func NewVersionCommand() *cobra.Command {
|
||||
err error
|
||||
)
|
||||
|
||||
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
||||
output, _ := cmd.Flags().GetString(flagOutput)
|
||||
switch strings.ToLower(output) {
|
||||
case "json":
|
||||
bz, err = json.Marshal(verInfo)
|
||||
@ -50,7 +52,7 @@ func NewVersionCommand() *cobra.Command {
|
||||
}
|
||||
|
||||
cmd.Flags().Bool(flagLong, false, "Print long version information")
|
||||
cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
|
||||
cmd.Flags().StringP(flagOutput, "o", "text", "Output format (text|json)")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/cmdtest"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
@ -144,7 +144,7 @@ func Test_runVersionCmd(t *testing.T) {
|
||||
_, mockOut := testutil.ApplyMockIO(cmd)
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
fmt.Sprintf("--%s=''", cli.OutputFlag),
|
||||
fmt.Sprintf("--%s=''", flags.FlagOutput),
|
||||
"--long=false",
|
||||
})
|
||||
|
||||
@ -153,7 +153,7 @@ func Test_runVersionCmd(t *testing.T) {
|
||||
mockOut.Reset()
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
fmt.Sprintf("--%s=json", cli.OutputFlag), "--long=true",
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput), "--long=true",
|
||||
})
|
||||
|
||||
info := version.NewInfo()
|
||||
|
||||
@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
cmtcli "github.com/cometbft/cometbft/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -23,7 +21,7 @@ func TxSignExec(clientCtx client.Context, from fmt.Stringer, filename string, ex
|
||||
}
|
||||
|
||||
cmd := cli.GetSignCommand()
|
||||
cmtcli.PrepareBaseCmd(cmd, "", "")
|
||||
cmd.PersistentFlags().String(flags.FlagHome, clientCtx.HomeDir, "directory for config and data")
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, cmd, append(args, extraArgs...))
|
||||
}
|
||||
@ -92,7 +90,7 @@ func TxAuxToFeeExec(clientCtx client.Context, filename string, extraArgs ...stri
|
||||
}
|
||||
|
||||
func QueryAccountExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{address.String(), fmt.Sprintf("--%s=json", cmtcli.OutputFlag)}
|
||||
args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)}
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAccountCmd(), append(args, extraArgs...))
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/math/unsafe"
|
||||
cfg "github.com/cometbft/cometbft/config"
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/cosmos/go-bip39"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -173,7 +172,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
|
||||
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "node's home directory")
|
||||
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
|
||||
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
|
||||
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
abci_server "github.com/cometbft/cometbft/abci/server"
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -146,7 +145,7 @@ func TestInitDefaultBondDenom(t *testing.T) {
|
||||
|
||||
cmd.SetArgs([]string{
|
||||
"appnode-test",
|
||||
fmt.Sprintf("--%s=%s", cli.HomeFlag, home),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagHome, home),
|
||||
fmt.Sprintf("--%s=testtoken", genutilcli.FlagDefaultBondDenom),
|
||||
})
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
@ -171,7 +170,7 @@ func TestEmptyState(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
|
||||
|
||||
cmd := genutilcli.InitCmd(testMbm, home)
|
||||
cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s", cli.HomeFlag, home)})
|
||||
cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s", flags.FlagHome, home)})
|
||||
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
@ -180,7 +179,7 @@ func TestEmptyState(t *testing.T) {
|
||||
os.Stdout = w
|
||||
|
||||
cmd = server.ExportCmd(nil, home)
|
||||
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", cli.HomeFlag, home)})
|
||||
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, home)})
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
outC := make(chan string)
|
||||
|
||||
@ -5,12 +5,12 @@ import (
|
||||
"fmt"
|
||||
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
"github.com/cometbft/cometbft/libs/cli"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -36,7 +36,7 @@ func ExecInitCmd(testMbm module.BasicManager, home string, cdc codec.Codec) erro
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)
|
||||
|
||||
cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s", cli.HomeFlag, home)})
|
||||
cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s", flags.FlagHome, home)})
|
||||
|
||||
return cmd.ExecuteContext(ctx)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user