aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean <darcys22@gmail.com>2019-01-07 16:56:50 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-01-07 16:56:50 +0800
commit428eabe28d1077356b16f25828d78d8693a766bb (patch)
tree01586ddc61853bef9f621e65ad7f3a0cc3f0c3d9
parente05d46807525f76dab83f84e9dfc9e4537398641 (diff)
downloaddexon-428eabe28d1077356b16f25828d78d8693a766bb.tar.gz
dexon-428eabe28d1077356b16f25828d78d8693a766bb.tar.zst
dexon-428eabe28d1077356b16f25828d78d8693a766bb.zip
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
-rw-r--r--cmd/geth/config.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/cmd/geth/config.go b/cmd/geth/config.go
index 59f759f0e..f1e281196 100644
--- a/cmd/geth/config.go
+++ b/cmd/geth/config.go
@@ -20,7 +20,6 @@ import (
"bufio"
"errors"
"fmt"
- "io"
"math/big"
"os"
"reflect"
@@ -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
}