From 2fb48e93eda3a8185ee92d8509559f2039c526ec Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 10 Jun 2020 09:59:40 -0700 Subject: [PATCH] Inline method call --- command/help.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/command/help.go b/command/help.go index e0599aa78..ad3561af2 100644 --- a/command/help.go +++ b/command/help.go @@ -8,11 +8,11 @@ import ( "github.com/spf13/cobra" ) -func rootDisplayCommandTypoHelp(command *cobra.Command, args []string) { +func rootHelpFunc(command *cobra.Command, args []string) { + // Display helpful error message in case subcommand name was mistyped. + // This matches Cobra's behavior for root command, which Cobra + // confusingly doesn't apply to nested commands. if command != RootCmd { - // Display helpful error message in case subcommand name was mistyped. - // This matches Cobra's behavior for root command, which Cobra - // confusingly doesn't apply to nested commands. if command.Parent() == RootCmd && len(args) >= 2 { if command.SuggestionsMinimumDistance <= 0 { command.SuggestionsMinimumDistance = 2 @@ -32,13 +32,9 @@ func rootDisplayCommandTypoHelp(command *cobra.Command, args []string) { oldOut := command.OutOrStdout() command.SetOut(errOut) - command.SetOut(oldOut) + defer command.SetOut(oldOut) } } -} - -func rootHelpFunc(command *cobra.Command, args []string) { - rootDisplayCommandTypoHelp(command, args) coreCommands := []string{} additionalCommands := []string{}