Commit 428eabe2 authored by Sean's avatar Sean Committed by Péter Szilágyi

cmd/geth: support dumpconfig optionally saving to file (#18327)

* Changed dumpConfig function to optionally save to file

* Added O_TRUNC flag to file open and cleaned up code
parent e05d4680
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"io"
"math/big" "math/big"
"os" "os"
"reflect" "reflect"
...@@ -198,7 +197,17 @@ func dumpConfig(ctx *cli.Context) error { ...@@ -198,7 +197,17 @@ func dumpConfig(ctx *cli.Context) error {
if err != nil { if err != nil {
return err 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 return nil
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment