Skip to content

Commit

Permalink
Fix default home
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-dydx committed Feb 12, 2024
1 parent ef2fbba commit 7ac06f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ func (c *ClientConfig) SetBroadcastMode(broadcastMode string) {
c.BroadcastMode = broadcastMode
}

// ReadDefaultValuesFromDefaultClientConfig reads default values from default client.toml file and updates them in client.Context
// The client.toml is then discarded.
func ReadDefaultValuesFromDefaultClientConfig(ctx client.Context) (client.Context, error) {
prevHomeDir := ctx.HomeDir
dir, err := os.MkdirTemp("", "simapp")
if err != nil {
return ctx, fmt.Errorf("couldn't create temp dir: %w", err)
}
defer os.RemoveAll(dir)

ctx.HomeDir = dir
ctx, err = ReadFromClientConfig(ctx)
if err != nil {
return ctx, fmt.Errorf("couldn't create client config: %w", err)
}

ctx.HomeDir = prevHomeDir
return ctx, nil
}

// ReadFromClientConfig reads values from client.toml file and updates them in client Context
func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
configPath := filepath.Join(ctx.HomeDir, "config")
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewRootCmd() *cobra.Command {
return err
}

initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
initClientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewRootCmd() *cobra.Command {
return err
}

clientCtx, err = config.ReadFromClientConfig(clientCtx)
clientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig(clientCtx)
if err != nil {
return err
}
Expand Down

0 comments on commit 7ac06f2

Please sign in to comment.