Skip to content

Commit 324d943

Browse files
gssbznumarcor
authored andcommitted
feat: make InitDefaultCompletionCmd public (spf13#1467)
1 parent 64c03db commit 324d943

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
@@ -930,7 +930,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
930930
// initialize help at the last point to allow for user overriding
931931
c.InitDefaultHelpCmd()
932932
// initialize completion at the last point to allow for user overriding
933-
c.initDefaultCompletionCmd()
933+
c.InitDefaultCompletionCmd()
934934

935935
args := c.args
936936

completions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,12 @@ func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*p
580580
return flag, trimmedArgs, lastArg, nil
581581
}
582582

583-
// initDefaultCompletionCmd adds a default 'completion' command to c.
583+
// InitDefaultCompletionCmd adds a default 'completion' command to c.
584584
// This function will do nothing if any of the following is true:
585585
// 1- the feature has been explicitly disabled by the program,
586586
// 2- c has no subcommands (to avoid creating one),
587587
// 3- c already has a 'completion' command provided by the program.
588-
func (c *Command) initDefaultCompletionCmd() {
588+
func (c *Command) InitDefaultCompletionCmd() {
589589
if c.CompletionOptions.DisableDefaultCmd || !c.HasSubCommands() {
590590
return
591591
}

doc/man_docs.go

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func manPrintOptions(buf io.StringWriter, command *cobra.Command) {
201201
func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
202202
cmd.InitDefaultHelpCmd()
203203
cmd.InitDefaultHelpFlag()
204+
cmd.InitDefaultCompletionCmd()
204205

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

doc/man_docs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestGenManSeeAlso(t *testing.T) {
131131
if err := assertNextLineEquals(scanner, ".PP"); err != nil {
132132
t.Fatalf("First line after SEE ALSO wasn't break-indent: %v", err)
133133
}
134-
if err := assertNextLineEquals(scanner, `\fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP`); err != nil {
134+
if err := assertNextLineEquals(scanner, `\fBroot-bbb(1)\fP, \fBroot-ccc(1)\fP, \fBroot-completion(1)\fP`); err != nil {
135135
t.Fatalf("Second line after SEE ALSO wasn't correct: %v", err)
136136
}
137137
}

doc/md_docs.go

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

5859
buf := new(bytes.Buffer)
5960
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)