From 1c2c02a5df19430e2497273111a35039177b7ce5 Mon Sep 17 00:00:00 2001 From: pkey <13101751+pkey@users.noreply.github.com> Date: Tue, 7 Apr 2026 12:00:16 +0100 Subject: [PATCH] fix: allow extensions use their own help command --- cliv2/cmd/cliv2/main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cliv2/cmd/cliv2/main.go b/cliv2/cmd/cliv2/main.go index 07bb5f1f18..e9401dd582 100644 --- a/cliv2/cmd/cliv2/main.go +++ b/cliv2/cmd/cliv2/main.go @@ -432,6 +432,8 @@ func createCommandsForWorkflows(rootCommand *cobra.Command, engine workflow.Engi // to preserve backwards compatibility we will need to relax flag validation parentCommand.FParseErrWhitelist.UnknownFlags = true parentCommand.Aliases = []string{"mcp-scan"} + case "redteam": + parentCommand.Annotations = map[string]string{"self-documented": "true"} } } } @@ -444,8 +446,6 @@ func prepareRootCommand() *cobra.Command { }, } - // help for all commands is handled by the legacy cli - // TODO: discuss how to move help to extensions helpCommand := cobra.Command{ Use: "help", RunE: help, @@ -457,8 +457,17 @@ func prepareRootCommand() *cobra.Command { rootCommand.SilenceUsage = true rootCommand.FParseErrWhitelist.UnknownFlags = true - // ensure that help and usage information comes from the legacy cli instead of cobra's default help - rootCommand.SetHelpFunc(func(c *cobra.Command, args []string) { _ = help(c, args) }) + // Extensions can opt in to handle their own help by setting the "self-documented" annotation. + // When set, Cobra renders help from the command's flagset and Short/Long fields. + // Commands without the annotation fall back to the legacy CLI help. + rootCommand.SetHelpFunc(func(c *cobra.Command, args []string) { + if c.Annotations["self-documented"] == "true" { + c.InitDefaultHelpFlag() + _ = c.Usage() + } else { + _ = help(c, args) + } + }) rootCommand.SetHelpCommand(&helpCommand) rootCommand.PersistentFlags().AddFlagSet(getGlobalFLags())