Improve documentation of DefaultShellCompDirective

This commit is contained in:
Harald Albers 2025-03-06 12:26:08 +00:00
parent 84a1965f14
commit 6ad4cd6904

View file

@ -319,7 +319,7 @@ cmd.RegisterFlagCompletionFunc("flag-name", cobra.NoFileCompletions)
``` ```
If you find that there are more situations where file completion should be turned off than If you find that there are more situations where file completion should be turned off than
when it is applicable, you can change the default `ShellCompDirective` for a command when it is applicable, you can recursively change the default `ShellCompDirective` for a command
and its subcommands to `ShellCompDirectiveNoFileComp`: and its subcommands to `ShellCompDirectiveNoFileComp`:
```go ```go
@ -333,6 +333,8 @@ flags where file completion is applicable. For example:
cmd.RegisterFlagCompletionFunc("flag-name", cobra.FixedCompletions(nil, ShellCompDirectiveDefault)) cmd.RegisterFlagCompletionFunc("flag-name", cobra.FixedCompletions(nil, ShellCompDirectiveDefault))
``` ```
To change the default directive for the entire program, set the DefaultShellCompDirective on the root command.
#### Debugging #### Debugging
You can also easily debug your Go completion code for flags: You can also easily debug your Go completion code for flags: