Config flag upgrade (#5491)

* allowing different values other than strings

* updated readme

* ops

* better error msg
This commit is contained in:
Enrique Jose Avila Asapche 2022-09-26 05:10:14 +03:00 committed by GitHub
parent fdb83de6f5
commit 511a5373f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -192,36 +192,36 @@ C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin
You can set Erigon flags through a YAML or TOML configuration file with the flag `--config`. The flags set in the configuration You can set Erigon flags through a YAML or TOML configuration file with the flag `--config`. The flags set in the configuration
file can be overwritten by writing the flags directly on Erigon command line file can be overwritten by writing the flags directly on Erigon command line
## Example ### Example
`./build/bin/erigon --config ./config.yaml --chain=goerli `./build/bin/erigon --config ./config.yaml --chain=goerli
Assuming we have `chain : "mainnet" in our configuration file, by adding `--chain=goerli` allows the overwrite of the flag inside Assuming we have `chain : "mainnet" in our configuration file, by adding `--chain=goerli` allows the overwrite of the flag inside
of the yaml configuration file and sets the chain to goerli of the yaml configuration file and sets the chain to goerli
## TOML ### TOML
Example of setting up TOML config file Example of setting up TOML config file
``` ```
`datadir = 'your datadir' `datadir = 'your datadir'
port = "1111" port = 1111
chain = "mainnet" chain = "mainnet"
http = "true" http = true
"private.api.addr"="localhost:9090" "private.api.addr"="localhost:9090"
"http.api" = ["eth","debug","net"] "http.api" = ["eth","debug","net"]
``` ```
## YAML ### YAML
Example of setting up a YAML config file Example of setting up a YAML config file
``` ```
datadir : 'your datadir' datadir : 'your datadir'
port : "1111" port : 1111
chain : "mainnet" chain : "mainnet"
http : "true" http : true
private.api.addr : "localhost:9090" private.api.addr : "localhost:9090"
http.api : ["eth","debug","net"] http.api : ["eth","debug","net"]

View File

@ -101,16 +101,17 @@ func setFlagsFromConfigFile(ctx *cli.Context, filePath string) error {
sliceInterface := value.([]interface{}) sliceInterface := value.([]interface{})
s := make([]string, len(sliceInterface)) s := make([]string, len(sliceInterface))
for i, v := range sliceInterface { for i, v := range sliceInterface {
s[i] = v.(string) s[i] = fmt.Sprintf("%v", v)
} }
err := ctx.GlobalSet(key, strings.Join(s, ",")) err := ctx.GlobalSet(key, strings.Join(s, ","))
if err != nil { if err != nil {
return err return fmt.Errorf("failed setting %s flag with values=%s error=%s", key, s, err)
} }
} else { } else {
err := ctx.GlobalSet(key, value.(string)) err := ctx.GlobalSet(key, fmt.Sprintf("%v", value))
if err != nil { if err != nil {
return err return fmt.Errorf("failed setting %s flag with value=%v error=%s", key, value, err)
} }
} }
} }