Add home default to other commands. (#6789)

* Add home default to other commands.

* add defaultNodeHome to rest of commands

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Jonathan Gimeno 2020-07-20 17:12:33 +02:00 committed by GitHub
parent 2247465fa3
commit 54141887b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 31 additions and 28 deletions

View File

@ -34,7 +34,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
config.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub)
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
// Prepare a keybase
kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
@ -84,7 +84,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
func Test_runAddCmdLedger(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
// Prepare a keybase

View File

@ -17,7 +17,7 @@ import (
func Test_runAddCmdBasic(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)

View File

@ -14,8 +14,12 @@ import (
)
func Test_runDeleteCmd(t *testing.T) {
// Now add a temporary keybase
kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)
cmd := DeleteKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands(kbHome).PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
yesF, _ := cmd.Flags().GetBool(flagYes)
@ -26,9 +30,6 @@ func Test_runDeleteCmd(t *testing.T) {
fakeKeyName1 := "runDeleteCmd_Key1"
fakeKeyName2 := "runDeleteCmd_Key2"
// Now add a temporary keybase
kbHome, cleanUp := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp)
path := sdk.GetConfig().GetFullFundraiserPath()

View File

@ -16,7 +16,7 @@ import (
func Test_runExportCmd(t *testing.T) {
cmd := ExportKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
// Now add a temporary keybase

View File

@ -16,7 +16,7 @@ import (
func Test_runImportCmd(t *testing.T) {
cmd := ImportKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
// Now add a temporary keybase

View File

@ -16,7 +16,7 @@ import (
func Test_runListCmd(t *testing.T) {
cmd := ListKeysCmd()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
kbHome1, cleanUp1 := testutil.NewTestCaseDir(t)
t.Cleanup(cleanUp1)

View File

@ -16,7 +16,7 @@ import (
func Test_runMigrateCmd(t *testing.T) {
cmd := AddKeyCommand()
_ = testutil.ApplyMockIODiscardOutErr(cmd)
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
kbHome, kbCleanUp := testutil.NewTestCaseDir(t)
copy.Copy("testdata", kbHome)
@ -32,7 +32,7 @@ func Test_runMigrateCmd(t *testing.T) {
assert.NoError(t, cmd.Execute())
cmd = MigrateCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
cmd.SetArgs([]string{

View File

@ -9,7 +9,7 @@ import (
// Commands registers a sub-tree of commands to interact with
// local private key storage.
func Commands() *cobra.Command {
func Commands(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "keys",
Short: "Manage your application's keys",
@ -50,7 +50,7 @@ The pass backend requires GnuPG: https://gnupg.org/
MigrateCommand(),
)
cmd.PersistentFlags().String(flags.FlagHome, "", "The application home directory")
cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.PersistentFlags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)")
cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)")

View File

@ -7,7 +7,7 @@ import (
)
func TestCommands(t *testing.T) {
rootCommands := Commands()
rootCommands := Commands("home")
assert.NotNil(t, rootCommands)
// Commands are registered

View File

@ -37,7 +37,7 @@ func Test_showKeysCmd(t *testing.T) {
func Test_runShowCmd(t *testing.T) {
cmd := ShowKeysCmd()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
cmd.SetArgs([]string{"invalid"})

View File

@ -23,7 +23,7 @@ const (
)
// ExportCmd dumps app state to JSON.
func ExportCmd(appExporter AppExporter) *cobra.Command {
func ExportCmd(appExporter AppExporter, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "Export state to JSON",
@ -103,7 +103,7 @@ func ExportCmd(appExporter AppExporter) *cobra.Command {
},
}
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)")
cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
cmd.Flags().StringSlice(flagJailWhitelist, []string{}, "List of validators to not jail state export")

View File

@ -59,7 +59,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
cmd := ExportCmd(
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
return app.ExportAppStateAndValidators(true, []string{})
})
}, tempDir)
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)

View File

@ -48,7 +48,7 @@ const (
// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
func StartCmd(appCreator AppCreator) *cobra.Command {
func StartCmd(appCreator AppCreator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Run the full node",
@ -101,7 +101,7 @@ which accepts a path for the resulting pprof file.
},
}
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with tendermint")
cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address")
cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")

View File

@ -11,6 +11,8 @@ import (
"syscall"
"time"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
tmcfg "github.com/tendermint/tendermint/config"
@ -177,11 +179,11 @@ func AddCommands(rootCmd *cobra.Command, appCreator AppCreator, appExport AppExp
)
rootCmd.AddCommand(
StartCmd(appCreator),
StartCmd(appCreator, simapp.DefaultNodeHome),
UnsafeResetAllCmd(),
flags.LineBreak,
tendermintCmd,
ExportCmd(appExport),
ExportCmd(appExport, simapp.DefaultNodeHome),
flags.LineBreak,
version.NewVersionCommand(),
)

View File

@ -27,7 +27,7 @@ const (
)
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
func AddGenesisAccountCmd() *cobra.Command {
func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Short: "Add a genesis account to genesis.json",
@ -157,7 +157,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
},
}
cmd.Flags().String(flags.FlagHome, "", "The application home directory")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")

View File

@ -79,7 +79,7 @@ func init() {
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics),
AddGenesisAccountCmd(),
AddGenesisAccountCmd(simapp.DefaultNodeHome),
cli.NewCompletionCmd(rootCmd, true),
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
@ -92,7 +92,7 @@ func init() {
rpc.StatusCommand(),
queryCommand(),
txCommand(),
keys.Commands(),
keys.Commands(simapp.DefaultNodeHome),
)
}

View File

@ -126,7 +126,7 @@ func TestEmptyState(t *testing.T) {
r, w, _ := os.Pipe()
os.Stdout = w
cmd = server.ExportCmd(nil)
cmd = server.ExportCmd(nil, home)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", cli.HomeFlag, home)})
require.NoError(t, cmd.ExecuteContext(ctx))