From 1e47c757c2f1c21fdd6e713de546a4b9c9f6e920 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Thu, 31 May 2018 16:59:51 -0700 Subject: [PATCH] command/agent: don't re-parse the flags on reload --- command/agent/agent.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 2dc7af20c..90a040db8 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -61,7 +61,6 @@ type cmd struct { versionPrerelease string versionHuman string shutdownCh <-chan struct{} - args []string flagArgs config.Flags logFilter *logutils.LevelFilter logOutput io.Writer @@ -85,14 +84,6 @@ func (c *cmd) Run(args []string) int { // readConfig is responsible for setup of our configuration using // the command line and any file configs func (c *cmd) readConfig() *config.RuntimeConfig { - if err := c.flags.Parse(c.args); err != nil { - if !strings.Contains(err.Error(), "help requested") { - c.UI.Error(fmt.Sprintf("error parsing flags: %v", err)) - } - return nil - } - c.flagArgs.Args = c.flags.Args() - b, err := config.NewBuilder(c.flagArgs) if err != nil { c.UI.Error(err.Error()) @@ -315,7 +306,13 @@ func startupTelemetry(conf *config.RuntimeConfig) (*metrics.InmemSink, error) { func (c *cmd) run(args []string) int { // Parse our configs - c.args = args + if err := c.flags.Parse(args); err != nil { + if !strings.Contains(err.Error(), "help requested") { + c.UI.Error(fmt.Sprintf("error parsing flags: %v", err)) + } + return 1 + } + c.flagArgs.Args = c.flags.Args() config := c.readConfig() if config == nil { return 1 @@ -506,7 +503,7 @@ func (c *cmd) handleReload(agent *agent.Agent, cfg *config.RuntimeConfig) (*conf "Failed to reload configs: %v", err)) } - return cfg, errs + return newCfg, errs } func (c *cmd) Synopsis() string {