Skip to content

Commit d910441

Browse files
gssbznhoshsadiq
authored andcommitted
feat: make InitDefaultCompletionCmd public
I also took the liberty to directly call it when generating docs as it seems that was already the case for `InitDefaultHelpCmd` Merge spf13/cobra#1467 closes #1464
1 parent f800c15 commit d910441

File tree

7 files changed

+8
-4
lines changed

7 files changed

+8
-4
lines changed

command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
953953
// initialize help at the last point to allow for user overriding
954954
c.InitDefaultHelpCmd()
955955
// initialize completion at the last point to allow for user overriding
956-
c.initDefaultCompletionCmd()
956+
c.InitDefaultCompletionCmd()
957957

958958
args := c.args
959959

completions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,12 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
598598
return flag, trimmedArgs, lastArg, nil
599599
}
600600

601-
// initDefaultCompletionCmd adds a default 'completion' command to c.
601+
// InitDefaultCompletionCmd adds a default 'completion' command to c.
602602
// This function will do nothing if any of the following is true:
603603
// 1- the feature has been explicitly disabled by the program,
604604
// 2- c has no subcommands (to avoid creating one),
605605
// 3- c already has a 'completion' command provided by the program.
606-
func (c *Command) initDefaultCompletionCmd() {
606+
func (c *Command) InitDefaultCompletionCmd() {
607607
if c.CompletionOptions.DisableDefaultCmd || !c.HasSubCommands() {
608608
return
609609
}

doc/man_docs.go

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func manPrintOptions(buf io.StringWriter, command *cobra.Command) {
234234
func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
235235
cmd.InitDefaultHelpCmd()
236236
cmd.InitDefaultHelpFlag()
237+
cmd.InitDefaultCompletionCmd()
237238

238239
// something like `rootcmd-subcmd1-subcmd2`
239240
dashCommandName := strings.Replace(cmd.CommandPath(), " ", "-", -1)

doc/man_docs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestGenManSeeAlso(t *testing.T) {
195195
if err := assertNextLineEquals(scanner, ".PP"); err != nil {
196196
t.Fatalf("First line after SEE ALSO wasn't break-indent: %v", err)
197197
}
198-
if err := assertNextLineEquals(scanner, `\fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP`); err != nil {
198+
if err := assertNextLineEquals(scanner, `\fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP, \fBroot-completion(1)\fP`); err != nil {
199199
t.Fatalf("Second line after SEE ALSO wasn't correct: %v", err)
200200
}
201201
}

doc/md_docs.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func GenMarkdown(cmd *cobra.Command, w io.Writer) error {
5353
func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
5454
cmd.InitDefaultHelpCmd()
5555
cmd.InitDefaultHelpFlag()
56+
cmd.InitDefaultCompletionCmd()
5657

5758
buf := new(bytes.Buffer)
5859
name := cmd.CommandPath()

doc/rest_docs.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func GenReST(cmd *cobra.Command, w io.Writer) error {
6161
func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, string) string) error {
6262
cmd.InitDefaultHelpCmd()
6363
cmd.InitDefaultHelpFlag()
64+
cmd.InitDefaultCompletionCmd()
6465

6566
buf := new(bytes.Buffer)
6667
name := cmd.CommandPath()

doc/yaml_docs.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func GenYaml(cmd *cobra.Command, w io.Writer) error {
9292
func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
9393
cmd.InitDefaultHelpCmd()
9494
cmd.InitDefaultHelpFlag()
95+
cmd.InitDefaultCompletionCmd()
9596

9697
yamlDoc := cmdDoc{}
9798
yamlDoc.Name = cmd.CommandPath()

0 commit comments

Comments
 (0)