Skip to content

Commit d578aa1

Browse files
authored
fix gen-doc to deal with hidden commands (#572)
1 parent 2e52f4b commit d578aa1

9 files changed

+27
-22
lines changed

doc/polycli_ulxly_bridge.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ The command also inherits flags from parent commands.
5151
5252
## See also
5353
54-
- [polycli ulxly ](polycli_ulxly_.md) -
55-
- [polycli ulxly bridge asset](polycli_ulxly__bridge_asset.md) - Move ETH or an ERC20 between to chains
54+
- [polycli ulxly bridge asset](polycli_ulxly_bridge_asset.md) - Move ETH or an ERC20 between to chains
5655
57-
- [polycli ulxly bridge message](polycli_ulxly__bridge_message.md) - Send some ETH along with data from one chain to another chain
56+
- [polycli ulxly bridge message](polycli_ulxly_bridge_message.md) - Send some ETH along with data from one chain to another chain
5857
59-
- [polycli ulxly bridge weth](polycli_ulxly__bridge_weth.md) - For L2's that use a gas token, use this to transfer WETH to another chain
58+
- [polycli ulxly bridge weth](polycli_ulxly_bridge_weth.md) - For L2's that use a gas token, use this to transfer WETH to another chain
6059

doc/polycli_ulxly_bridge_asset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ The command also inherits flags from parent commands.
127127
128128
## See also
129129
130-
- [polycli ulxly bridge](polycli_ulxly__bridge.md) - Commands for moving funds and sending messages from one chain to another
130+
- [polycli ulxly bridge](polycli_ulxly_bridge.md) - Commands for moving funds and sending messages from one chain to another

doc/polycli_ulxly_bridge_message.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ The command also inherits flags from parent commands.
124124
125125
## See also
126126
127-
- [polycli ulxly bridge](polycli_ulxly__bridge.md) - Commands for moving funds and sending messages from one chain to another
127+
- [polycli ulxly bridge](polycli_ulxly_bridge.md) - Commands for moving funds and sending messages from one chain to another

doc/polycli_ulxly_bridge_weth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ The command also inherits flags from parent commands.
9393
9494
## See also
9595
96-
- [polycli ulxly bridge](polycli_ulxly__bridge.md) - Commands for moving funds and sending messages from one chain to another
96+
- [polycli ulxly bridge](polycli_ulxly_bridge.md) - Commands for moving funds and sending messages from one chain to another

doc/polycli_ulxly_claim-everything.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- [Description](#description)
88
- [Usage](#usage)
99
- [Flags](#flags)
10-
- [See Also](#see-also)
1110

1211
## Description
1312

@@ -51,6 +50,3 @@ The command also inherits flags from parent commands.
5150
700 Trace (default 500)
5251
```
5352
54-
## See also
55-
56-
- [polycli ulxly ](polycli_ulxly_.md) -

doc/polycli_ulxly_claim.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ The command also inherits flags from parent commands.
5050
5151
## See also
5252
53-
- [polycli ulxly ](polycli_ulxly_.md) -
54-
- [polycli ulxly claim asset](polycli_ulxly__claim_asset.md) - Claim a deposit
53+
- [polycli ulxly claim asset](polycli_ulxly_claim_asset.md) - Claim a deposit
5554
56-
- [polycli ulxly claim message](polycli_ulxly__claim_message.md) - Claim a message
55+
- [polycli ulxly claim message](polycli_ulxly_claim_message.md) - Claim a message
5756

doc/polycli_ulxly_claim_asset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ The command also inherits flags from parent commands.
136136
137137
## See also
138138
139-
- [polycli ulxly claim](polycli_ulxly__claim.md) - Commands for claiming deposits on a particular chain
139+
- [polycli ulxly claim](polycli_ulxly_claim.md) - Commands for claiming deposits on a particular chain

doc/polycli_ulxly_claim_message.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ The command also inherits flags from parent commands.
141141
142142
## See also
143143
144-
- [polycli ulxly claim](polycli_ulxly__claim.md) - Commands for claiming deposits on a particular chain
144+
- [polycli ulxly claim](polycli_ulxly_claim.md) - Commands for claiming deposits on a particular chain

docutil/doc.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func genMarkdownDoc(cmd *cobra.Command, dir string) error {
2626
}
2727

2828
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".md"
29-
// clean dupped underscores
30-
for strings.Contains(basename, "__") {
31-
basename = strings.ReplaceAll(basename, "__", "_")
32-
}
29+
basename = cleanDuppedSeparator(basename, "_")
3330
filename := filepath.Join(dir, basename)
3431
f, err := os.Create(filename)
3532
if err != nil {
@@ -139,7 +136,7 @@ func printFlags(buf *bytes.Buffer, cmd *cobra.Command, name string) error {
139136
// both not deprecated and not the autogenerated help command.
140137
// This is a fork of Cobra's `hasSeeAlso` function.
141138
func hasSeeAlso(cmd *cobra.Command) bool {
142-
if cmd.HasParent() {
139+
if cmd.HasParent() && cmd.Parent().IsAvailableCommand() && !cmd.Parent().IsAdditionalHelpTopicCommand() {
143140
return true
144141
}
145142
for _, c := range cmd.Commands() {
@@ -153,11 +150,14 @@ func hasSeeAlso(cmd *cobra.Command) bool {
153150

154151
// Print See Also section.
155152
func printSeeAlso(buf *bytes.Buffer, cmd *cobra.Command, name string, linkHandler func(s string) string) {
156-
if cmd.HasParent() {
153+
if cmd.HasParent() && cmd.Parent().IsAvailableCommand() && !cmd.Parent().IsAdditionalHelpTopicCommand() {
157154
parent := cmd.Parent()
158155
pname := parent.CommandPath()
156+
pname = cleanDuppedSeparator(pname, " ")
157+
pname = strings.TrimSuffix(pname, " ")
159158
link := pname + ".md"
160159
link = strings.Replace(link, " ", "_", -1)
160+
link = cleanDuppedSeparator(link, "_")
161161
buf.WriteString(fmt.Sprintf("\n- [%s](%s) - %s", pname, linkHandler(link), parent.Short))
162162
cmd.VisitParents(func(c *cobra.Command) {
163163
if c.DisableAutoGenTag {
@@ -174,8 +174,11 @@ func printSeeAlso(buf *bytes.Buffer, cmd *cobra.Command, name string, linkHandle
174174
continue
175175
}
176176
cname := name + " " + child.Name()
177+
cname = cleanDuppedSeparator(cname, " ")
178+
cname = strings.TrimSuffix(cname, " ")
177179
link := cname + ".md"
178180
link = strings.Replace(link, " ", "_", -1)
181+
link = cleanDuppedSeparator(link, "_")
179182
buf.WriteString(fmt.Sprintf("\n- [%s](%s) - %s\n", cname, linkHandler(link), child.Short))
180183
}
181184
buf.WriteString("\n")
@@ -186,3 +189,11 @@ type byName []*cobra.Command
186189
func (s byName) Len() int { return len(s) }
187190
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
188191
func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
192+
193+
func cleanDuppedSeparator(s string, sep string) string {
194+
// clean dupped separators
195+
for strings.Contains(s, sep+sep) {
196+
s = strings.ReplaceAll(s, sep+sep, sep)
197+
}
198+
return s
199+
}

0 commit comments

Comments
 (0)