Skip to content

Commit

Permalink
cmd/geth: support dumpconfig optionally saving to file (#18327)
Browse files Browse the repository at this point in the history
* Changed dumpConfig function to optionally save to file

* Added O_TRUNC flag to file open and cleaned up code
  • Loading branch information
darcys22 authored and karalabe committed Jan 7, 2019
1 parent e05d468 commit 428eabe
Showing 1 changed file with 12 additions and 3 deletions.
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)

return nil
}

0 comments on commit 428eabe

Please sign in to comment.