cobra
cobra copied to clipboard
Feature request: Set a default completion function
In my experience, not many flags actually require completion of files.
Some have dynamic completions, but a great deal of them take free-form string parameters where no completion can be offered.
Unfortunately, the default completion for a flag with no completion function in Cobra is file completion.
This forces me to register a cobra.NoFileCompletions
for each flag of that category.
As an example, completion for docker run
has 56 flags where no meaningful FlagCompletionFunc exists.
In a first attempt, I registered 56 handlers with cmd.RegisterFlagCompletionFunc("flag-name", cobra.NoFileCompletions)
just to silence their file completion.
Following a hint of @thaJeztah, I replaced them with a programmatically installed default handler, see here.
I would very much welcome a solution in Cobra, where I can set a default handler on command level, something like
cmd.CompletionOptions.DefaultCompHandler = cobra.NoFileCompletions
With this feature, I'd only have to define the completion functions for flags that actually have meaningful completions.
/cc @thaJeztah