diff --git a/slasher/BUILD.bazel b/slasher/BUILD.bazel index 980a738a476d..c72727f82d68 100644 --- a/slasher/BUILD.bazel +++ b/slasher/BUILD.bazel @@ -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", ], ) @@ -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", ], ) diff --git a/slasher/main.go b/slasher/main.go index 6f17a1644527..8baed4c7e878 100644 --- a/slasher/main.go +++ b/slasher/main.go @@ -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") @@ -48,6 +49,7 @@ var appFlags = []cli.Flag{ cmd.LogFormat, cmd.ClearDB, cmd.ForceClearDB, + cmd.ConfigFileFlag, debug.PProfFlag, debug.PProfAddrFlag, debug.PProfPortFlag, @@ -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": diff --git a/slasher/usage.go b/slasher/usage.go index aeb7f151b6c1..35d77e51948d 100644 --- a/slasher/usage.go +++ b/slasher/usage.go @@ -54,6 +54,7 @@ var appHelpFlagGroups = []flagGroup{ cmd.LogFileName, cmd.ForceClearDB, cmd.ClearDB, + cmd.ConfigFileFlag, }, }, {