X Tutup
Skip to content

Commit 52959ab

Browse files
committed
Clean up and refactor unused doc generation code
1 parent f8ce68f commit 52959ab

File tree

5 files changed

+27
-39
lines changed

5 files changed

+27
-39
lines changed

internal/docs/man.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,25 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
218218
}
219219
return buf.Bytes()
220220
}
221+
222+
// Test to see if we have a reason to print See Also information in docs
223+
// Basically this is a test for a parent command or a subcommand which is
224+
// both not deprecated and not the autogenerated help command.
225+
func hasSeeAlso(cmd *cobra.Command) bool {
226+
if cmd.HasParent() {
227+
return true
228+
}
229+
for _, c := range cmd.Commands() {
230+
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
231+
continue
232+
}
233+
return true
234+
}
235+
return false
236+
}
237+
238+
type byName []*cobra.Command
239+
240+
func (s byName) Len() int { return len(s) }
241+
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
242+
func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }

internal/docs/man_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestGenManSeeAlso(t *testing.T) {
109109
func TestManPrintFlagsHidesShortDeperecated(t *testing.T) {
110110
c := &cobra.Command{}
111111
c.Flags().StringP("foo", "f", "default", "Foo flag")
112-
c.Flags().MarkShorthandDeprecated("foo", "don't use it no more")
112+
_ = c.Flags().MarkShorthandDeprecated("foo", "don't use it no more")
113113

114114
buf := new(bytes.Buffer)
115115
manPrintFlags(buf, c.Flags())

internal/docs/markdown_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestGenMdDoc(t *testing.T) {
2222
checkStringContains(t, output, echoCmd.Example)
2323
checkStringContains(t, output, "boolone")
2424
checkStringContains(t, output, "rootflag")
25+
checkStringOmits(t, output, rootCmd.Short)
26+
checkStringOmits(t, output, echoSubCmd.Short)
2527
checkStringOmits(t, output, deprecatedCmd.Short)
2628
checkStringContains(t, output, "Options inherited from parent commands")
2729
}
@@ -57,6 +59,8 @@ func TestGenMdNoHiddenParents(t *testing.T) {
5759
checkStringContains(t, output, echoCmd.Example)
5860
checkStringContains(t, output, "boolone")
5961
checkStringOmits(t, output, "rootflag")
62+
checkStringOmits(t, output, rootCmd.Short)
63+
checkStringOmits(t, output, echoSubCmd.Short)
6064
checkStringOmits(t, output, deprecatedCmd.Short)
6165
checkStringOmits(t, output, "Options inherited from parent commands")
6266
}

internal/docs/utils.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)
X Tutup