Skip to content

Commit e47c0f6

Browse files
committed
fix command names
1 parent aab474a commit e47c0f6

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

cli/generate_docs.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cli
44

55
import (
6+
"bytes"
67
"os"
78
"path"
89
"strings"
@@ -13,37 +14,55 @@ import (
1314

1415
var isDocsBuild = true
1516

16-
func generateDocs(cmd *cobra.Command, filename string, title string) {
17+
func generateDocs(cmd *cobra.Command, title string) {
1718
cmd.DisableAutoGenTag = true
1819

1920
// create docs directory
2021
_ = os.Mkdir("./docs", 0755)
2122

22-
err := doc.GenMarkdownTreeCustom(cmd, "./docs",
23-
func(_ string) string {
24-
return `---
25-
title: ` + title + `
26-
---
27-
28-
`
29-
},
30-
func(name string) string {
31-
// err := doc.GenMarkdownCustom(cmd, out, func(name string) string {
32-
base := strings.TrimSuffix(name, path.Ext(name))
33-
return "/cli/" + strings.ToLower(base) + "/"
34-
})
23+
out := new(bytes.Buffer)
24+
25+
err := doc.GenMarkdownCustom(cmd, out, func(name string) string {
26+
// err := doc.GenMarkdownCustom(cmd, out, func(name string) string {
27+
base := strings.TrimSuffix(name, path.Ext(name))
28+
return "/cli/" + strings.ToLower(base) + "/"
29+
})
3530
if err != nil {
3631
panic(err)
3732
}
3833

34+
// Define the text to be replaced and the replacement text
35+
oldText := []byte("## " + title)
36+
newText := []byte("---\ntitle: " + title + "\n---")
37+
38+
// Perform the replacement on the buffer's content
39+
updatedContent := bytes.Replace(out.Bytes(), oldText, newText, 1)
40+
41+
// Reset the buffer and write the updated content back to it
42+
out.Reset()
43+
out.Write(updatedContent)
44+
45+
// write markdown to file
46+
file, err := os.Create("./docs/" + strings.ReplaceAll(title, " ", "_") + ".md")
47+
if err != nil {
48+
panic(err)
49+
}
50+
51+
_, err = file.Write(out.Bytes())
52+
if err != nil {
53+
panic(err)
54+
}
55+
56+
defer file.Close()
57+
3958
// if command has subcommands, generate markdown for each subcommand
4059
if cmd.HasSubCommands() {
4160
for _, c := range cmd.Commands() {
4261
// if c.Use starts with "help", skip it
43-
if strings.HasPrefix(c.Use, "help") {
62+
if c.Name() == "help" {
4463
continue
4564
}
46-
generateDocs(c, filename, title+" "+c.Use)
65+
generateDocs(c, title+" "+c.Name())
4766
}
4867
}
4968
}

cli/generate_docs_default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import "github.com/spf13/cobra"
66

77
var isDocsBuild = false
88

9-
func generateDocs(_ *cobra.Command, _ string, _ string) {
9+
func generateDocs(_ *cobra.Command, _ string) {
1010
// do nothing if the build tag "docs" is not set
1111
}

cli/main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ func createMainCommand() *cobra.Command {
5959
cmd.AddCommand(versionCommand())
6060

6161
// Generate markdown documentation
62-
generateDocs(loginCommand(), "dispatch_login.md", "dispatch login")
63-
generateDocs(initCommand(), "dispatch_init.md", "dispatch init")
64-
generateDocs(switchCommand(DispatchConfigPath), "dispatch_switch.md", "dispatch switch")
65-
generateDocs(verificationCommand(), "dispatch_verification.md", "dispatch verification")
66-
generateDocs(runCommand(), "dispatch_run.md", "dispatch run")
67-
generateDocs(versionCommand(), "dispatch_version.md", "dispatch version")
62+
generateDocs(cmd, "dispatch")
6863

6964
return cmd
7065
}

0 commit comments

Comments
 (0)