forked from maticnetwork/bor
/
dumpconfig.go
68 lines (52 loc) · 1.91 KB
/
dumpconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cli
import (
"os"
"strings"
"github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum/internal/cli/server"
)
// DumpconfigCommand is for exporting user provided flags into a config file
type DumpconfigCommand struct {
*Meta2
}
// MarkDown implements cli.MarkDown interface
func (p *DumpconfigCommand) MarkDown() string {
items := []string{
"# Dumpconfig",
"The ```bor dumpconfig <your-favourite-flags>``` command will export the user provided flags into a configuration file",
}
return strings.Join(items, "\n\n")
}
// Help implements the cli.Command interface
func (c *DumpconfigCommand) Help() string {
return `Usage: bor dumpconfig <your-favourite-flags>
This command will will export the user provided flags into a configuration file`
}
// Synopsis implements the cli.Command interface
func (c *DumpconfigCommand) Synopsis() string {
return "Export configuration file"
}
// TODO: add flags for file location and format (toml, json, hcl) of the configuration file.
// Run implements the cli.Command interface
func (c *DumpconfigCommand) Run(args []string) int {
// Initialize an empty command instance to get flags
command := server.Command{}
flags := command.Flags()
if err := flags.Parse(args); err != nil {
c.UI.Error(err.Error())
return 1
}
userConfig := command.GetConfig()
// convert the big.Int and time.Duration fields to their corresponding Raw fields
userConfig.TxPool.RejournalRaw = userConfig.TxPool.Rejournal.String()
userConfig.TxPool.LifeTimeRaw = userConfig.TxPool.LifeTime.String()
userConfig.Sealer.GasPriceRaw = userConfig.Sealer.GasPrice.String()
userConfig.Gpo.MaxPriceRaw = userConfig.Gpo.MaxPrice.String()
userConfig.Gpo.IgnorePriceRaw = userConfig.Gpo.IgnorePrice.String()
userConfig.Cache.RejournalRaw = userConfig.Cache.Rejournal.String()
if err := toml.NewEncoder(os.Stdout).Encode(userConfig); err != nil {
c.UI.Error(err.Error())
return 1
}
return 0
}