Skip to content

Commit

Permalink
Add slasher config file flag (#5639)
Browse files Browse the repository at this point in the history
* Add slasher config file

* shorter line

* fix package dependencies

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
shayzluf and prylabs-bulldozer[bot] authored Apr 27, 2020
1 parent e3e9863 commit 4da7701
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions slasher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
"@in_gopkg_urfave_cli_v2//:go_default_library",
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
],
)

Expand Down Expand Up @@ -63,6 +64,7 @@ go_image(
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
"@in_gopkg_urfave_cli_v2//:go_default_library",
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
],
)

Expand Down
12 changes: 12 additions & 0 deletions slasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
"gopkg.in/urfave/cli.v2"
"gopkg.in/urfave/cli.v2/altsrc"
)

var log = logrus.WithField("prefix", "main")
Expand Down Expand Up @@ -48,6 +49,7 @@ var appFlags = []cli.Flag{
cmd.LogFormat,
cmd.ClearDB,
cmd.ForceClearDB,
cmd.ConfigFileFlag,
debug.PProfFlag,
debug.PProfAddrFlag,
debug.PProfPortFlag,
Expand All @@ -73,6 +75,16 @@ func main() {
app.Flags = appFlags
app.Action = startSlasher
app.Before = func(ctx *cli.Context) error {
// Load any flags from file, if specified.
if ctx.IsSet(cmd.ConfigFileFlag.Name) {
if err := altsrc.InitInputSourceWithContext(
appFlags,
altsrc.NewYamlSourceFromFlagFunc(
cmd.ConfigFileFlag.Name))(ctx); err != nil {
return err
}
}

format := ctx.String(cmd.LogFormat.Name)
switch format {
case "text":
Expand Down
1 change: 1 addition & 0 deletions slasher/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var appHelpFlagGroups = []flagGroup{
cmd.LogFileName,
cmd.ForceClearDB,
cmd.ClearDB,
cmd.ConfigFileFlag,
},
},
{
Expand Down

0 comments on commit 4da7701

Please sign in to comment.