Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed dumpConfig function to optionally save to file #18327

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bufio"
"errors"
"fmt"
"io"
"math/big"
"os"
"reflect"
Expand Down Expand Up @@ -198,7 +197,17 @@ func dumpConfig(ctx *cli.Context) error {
if err != nil {
return err
}
io.WriteString(os.Stdout, comment)
os.Stdout.Write(out)

dump := os.Stdout
if ctx.NArg() > 0 {
dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer dump.Close()
}
dump.WriteString(comment)
dump.Write(out)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minot nitpick, might be a bit cleaner to put the stream into a variable and call the writes only once:

dump := os.Stdout
if ctx.NArg() > 0 {
	dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|O_TRUNC, 0644)
	if err != nil {
		return err
	}
	defer dump.Close()
}
dump.WriteString(comment)
dump.Write(out)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that code looks much cleaner. I've made updates below

return nil
}