From fcf30cc32823c8be9105c201c56b37bd85feaa2d Mon Sep 17 00:00:00 2001 From: Calvin Leung Huang Date: Mon, 11 Nov 2019 15:32:11 -0800 Subject: [PATCH] debug: ignore invalid target flags (#7860) --- command/debug.go | 7 +++++++ command/debug_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/command/debug.go b/command/debug.go index 3fd54ea4f9..8cec89f9c5 100644 --- a/command/debug.go +++ b/command/debug.go @@ -389,6 +389,13 @@ func (c *DebugCommand) preflight(rawArgs []string) (string, error) { if len(c.flagTargets) == 0 { c.flagTargets = c.defaultTargets() + } else { + // Check for any invalid targets and ignore them if found + invalidTargets := strutil.Difference(c.flagTargets, c.defaultTargets(), true) + if len(invalidTargets) != 0 { + c.UI.Info(fmt.Sprintf("Ignoring invalid targets: %s", strings.Join(invalidTargets, ", "))) + c.flagTargets = strutil.Difference(c.flagTargets, invalidTargets, true) + } } // Make sure we can talk to the server diff --git a/command/debug_test.go b/command/debug_test.go index a7a20278ec..5f1c22395a 100644 --- a/command/debug_test.go +++ b/command/debug_test.go @@ -61,6 +61,16 @@ func TestDebugCommand_Run(t *testing.T) { "Too many arguments", 1, }, + { + "invalid_target", + []string{ + "-duration=1s", + fmt.Sprintf("-output=%s/too_many_args", testDir), + "-target=foo", + }, + "Ignoring invalid targets: foo", + 0, + }, } for _, tc := range cases {