Skip to content

Commit

Permalink
Add home default to other commands. (cosmos#6789)
Browse files Browse the repository at this point in the history
* Add home default to other commands.

* add defaultNodeHome to rest of commands

Co-authored-by: Alexander Bezobchuk <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 20, 2020
1 parent 2247465 commit 5414188
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions client/keys/add_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions client/keys/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion client/keys/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions client/keys/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions client/keys/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)")

Expand Down
2 changes: 1 addition & 1 deletion client/keys/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestCommands(t *testing.T) {
rootCommands := Commands()
rootCommands := Commands("home")
assert.NotNil(t, rootCommands)

// Commands are registered
Expand Down
2 changes: 1 addition & 1 deletion client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
4 changes: 2 additions & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
)
Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -92,7 +92,7 @@ func init() {
rpc.StatusCommand(),
queryCommand(),
txCommand(),
keys.Commands(),
keys.Commands(simapp.DefaultNodeHome),
)
}

Expand Down
2 changes: 1 addition & 1 deletion x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 5414188

Please sign in to comment.