diff --git a/carapace.go b/carapace.go index 714139f69..1a85d3260 100644 --- a/carapace.go +++ b/carapace.go @@ -91,6 +91,11 @@ func (c Carapace) Standalone() { DisableDefaultCmd: true, } + if c.cmd.Annotations == nil { + c.cmd.Annotations = make(map[string]string) + } + c.cmd.Annotations["carapace_standalone"] = "true" + c.PreRun(func(cmd *cobra.Command, args []string) { if f := cmd.Flag("help"); f == nil { cmd.Flags().Bool("help", false, "") diff --git a/command.go b/command.go index ba89e5eed..bb6db5db2 100644 --- a/command.go +++ b/command.go @@ -33,7 +33,12 @@ func addCompletionCommand(cmd *cobra.Command) { panic("missing parent command") // this should never happen } - if s, err := complete(cmd.Parent(), args); err != nil { + parentCmd := cmd.Parent() + if parentCmd.Annotations["carapace_standalone"] == "true" { + parentCmd.RemoveCommand(cmd) + } + + if s, err := complete(parentCmd, args); err != nil { fmt.Fprintln(io.MultiWriter(cmd.OutOrStderr(), LOG.Writer()), err.Error()) } else { fmt.Fprintln(io.MultiWriter(cmd.OutOrStdout(), LOG.Writer()), s)