@@ -100,8 +100,12 @@ func GenDocs(cmd *cobra.Command, w io.Writer) error {
100
100
buf .WriteString (strings .Repeat ("=" , len (name )) + "\n " )
101
101
buf .WriteString (toc )
102
102
buf .WriteString ("\n " + cmd .Short + "\n " )
103
- if cmd .Long != "" {
104
- buf .WriteString ("\n " + cmd .Long + "\n " )
103
+ if long := cmd .Long ; long != "" {
104
+ // remove when https://github.com/spf13/cobra/pull/1495 is released
105
+ if strings .Contains (name , "completion bash" ) {
106
+ long = bashCompletionLong (cmd )
107
+ }
108
+ buf .WriteString ("\n " + long + "\n " )
105
109
}
106
110
buf .WriteString ("\n " )
107
111
@@ -160,6 +164,22 @@ func GenDocs(cmd *cobra.Command, w io.Writer) error {
160
164
return err
161
165
}
162
166
167
+ func bashCompletionLong (cmd * cobra.Command ) string {
168
+ return fmt .Sprintf (`
169
+ Generate the autocompletion script for the bash shell.
170
+ This script depends on the 'bash-completion' package.
171
+ If it is not installed already, you can install it via your OS's package manager.
172
+ To load completions in your current shell session:
173
+ $ source <(%[1]s completion bash)
174
+ To load completions for every new session, execute once:
175
+ Linux:
176
+ $ %[1]s completion bash > /etc/bash_completion.d/%[1]s
177
+ MacOS:
178
+ $ %[1]s completion bash > /usr/local/etc/bash_completion.d/%[1]s
179
+ You will need to start a new shell for this setup to take effect.
180
+ ` , cmd .Root ().Name ())
181
+ }
182
+
163
183
// Test to see if we have a reason to print See Also information in docs
164
184
// Basically this is a test for a parent command or a subcommand which is
165
185
// both not deprecated and not the autogenerated help command.
0 commit comments