diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index 5464e9ce3..814b5da5f 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -28,6 +28,8 @@ const ( anonymizedInvalidVerb = "{invalid verb}" lineLimitToShowFilter = 16 + + invalidCmdWithUsage = "error: unknown option `%s`\nusage: %s" ) var newLinePattern = regexp.MustCompile(`\r?\n`) @@ -168,8 +170,9 @@ func (e *DefaultExecutor) Execute(ctx context.Context) interactive.CoreMessage { reportedCmd = fmt.Sprintf("%s {invalid feature}", reportedCmd) } e.reportCommand(ctx, "", reportedCmd, false, cmdCtx) - msg := e.cmdsMapping.HelpMessageForVerb(cmdVerb) - return respond(msg, cmdCtx) + helpMsg := e.cmdsMapping.HelpMessageForVerb(cmdVerb) + responseMsg := fmt.Sprintf(invalidCmdWithUsage, cmdRes, helpMsg) + return respond(responseMsg, cmdCtx) } else { cmdToReport := string(cmdVerb) if cmdRes != "" { diff --git a/pkg/execute/mapping.go b/pkg/execute/mapping.go index a5c2165b8..f95068be6 100644 --- a/pkg/execute/mapping.go +++ b/pkg/execute/mapping.go @@ -14,7 +14,8 @@ import ( ) const ( - helpMsgHeader = "%s %s [feature]\n\nAvailable features:\n" + helpMsgHeaderWithFeatures = "%s %s [feature]\n\nAvailable features:\n" + helpMsgHeader = "%s %s" // noFeature is used for commands that have no features defined noFeature = "" // incompleteCmdMsg incomplete command response message @@ -127,8 +128,12 @@ func (m *CommandMapping) HelpMessageForVerb(verb command.Verb) string { } buf := new(bytes.Buffer) w := tabwriter.NewWriter(buf, 3, 0, 1, ' ', 0) + if len(cmd) > 0 && cmd[0].Name != "" { + fmt.Fprintf(w, helpMsgHeaderWithFeatures, api.MessageBotNamePlaceholder, verb) + } else { + fmt.Fprintf(w, helpMsgHeader, api.MessageBotNamePlaceholder, verb) + } - fmt.Fprintf(w, helpMsgHeader, api.MessageBotNamePlaceholder, verb) for _, feature := range cmd { aliases := removeEmptyFeatures(feature.Aliases) fmtStr := fmt.Sprintf("%s\t", feature.Name)