Skip to content

Commit 428eabe

Browse files
darcys22karalabe
authored andcommitted
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
1 parent e05d468 commit 428eabe

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cmd/geth/config.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bufio"
2121
"errors"
2222
"fmt"
23-
"io"
2423
"math/big"
2524
"os"
2625
"reflect"
@@ -198,7 +197,17 @@ func dumpConfig(ctx *cli.Context) error {
198197
if err != nil {
199198
return err
200199
}
201-
io.WriteString(os.Stdout, comment)
202-
os.Stdout.Write(out)
200+
201+
dump := os.Stdout
202+
if ctx.NArg() > 0 {
203+
dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
204+
if err != nil {
205+
return err
206+
}
207+
defer dump.Close()
208+
}
209+
dump.WriteString(comment)
210+
dump.Write(out)
211+
203212
return nil
204213
}

0 commit comments

Comments
 (0)