use urfave defaulting method for correct help text (#8972)

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
kasey 2021-06-02 14:47:47 -05:00 committed by GitHub
parent fc898d541f
commit 2b6c7e7b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -3,6 +3,8 @@
package flags package flags
import ( import (
"time"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -25,6 +27,7 @@ var (
// ScrapeIntervalFlag defines a flag for the frequency of scraping. // ScrapeIntervalFlag defines a flag for the frequency of scraping.
ScrapeIntervalFlag = &cli.DurationFlag{ ScrapeIntervalFlag = &cli.DurationFlag{
Name: "scrape-interval", Name: "scrape-interval",
Usage: "Frequency of scraping expressed as a duration, eg 2m or 1m5s. Default is 60s.", Usage: "Frequency of scraping expressed as a duration, eg 2m or 1m5s.",
Value: 60 * time.Second,
} }
) )

View File

@ -28,7 +28,6 @@ var appFlags = []cli.Flag{
flags.ClientStatsAPIURLFlag, flags.ClientStatsAPIURLFlag,
flags.ScrapeIntervalFlag, flags.ScrapeIntervalFlag,
} }
var scrapeInterval = 60 * time.Second
func main() { func main() {
app := cli.App{} app := cli.App{}
@ -101,10 +100,6 @@ func main() {
} }
func run(ctx *cli.Context) error { func run(ctx *cli.Context) error {
if ctx.IsSet(flags.ScrapeIntervalFlag.Name) {
scrapeInterval = ctx.Duration(flags.ScrapeIntervalFlag.Name)
}
var upd clientstats.Updater var upd clientstats.Updater
if ctx.IsSet(flags.ClientStatsAPIURLFlag.Name) { if ctx.IsSet(flags.ClientStatsAPIURLFlag.Name) {
u := ctx.String(flags.ClientStatsAPIURLFlag.Name) u := ctx.String(flags.ClientStatsAPIURLFlag.Name)
@ -124,7 +119,7 @@ func run(ctx *cli.Context) error {
scrapers = append(scrapers, clientstats.NewValidatorScraper(u)) scrapers = append(scrapers, clientstats.NewValidatorScraper(u))
} }
ticker := time.NewTicker(scrapeInterval) ticker := time.NewTicker(ctx.Duration(flags.ScrapeIntervalFlag.Name))
for { for {
select { select {
case <-ticker.C: case <-ticker.C: