From 458d93ea7eccc9360377ece6a053b8426831cb0b Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:55:49 +0200 Subject: [PATCH] docs: fix the rclone root command header levels --- cmd/gendocs/gendocs.go | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/gendocs/gendocs.go b/cmd/gendocs/gendocs.go index 6b6e85fca..aeba01566 100644 --- a/cmd/gendocs/gendocs.go +++ b/cmd/gendocs/gendocs.go @@ -178,33 +178,33 @@ rclone.org website.`, } doc := string(b) - var out strings.Builder - if groupsString := cmd.Annotations["groups"]; groupsString != "" { - groups := flags.All.Include(groupsString) - for _, group := range groups.Groups { - if group.Flags.HasFlags() { - _, _ = fmt.Fprintf(&out, "\n### %s Options\n\n", group.Name) - _, _ = fmt.Fprintf(&out, "%s\n\n", group.Help) - _, _ = fmt.Fprintln(&out, "```") - _, _ = out.WriteString(group.Flags.FlagUsages()) - _, _ = fmt.Fprintln(&out, "```") - } - } - } - _, _ = out.WriteString(` -See the [global flags page](/flags/) for global options not listed here. - -`) - startCut := strings.Index(doc, `### Options inherited from parent commands`) endCut := strings.Index(doc, `### SEE ALSO`) if startCut < 0 || endCut < 0 { - if name == "rclone.md" { - return nil + if name != "rclone.md" { + return fmt.Errorf("internal error: failed to find cut points: startCut = %d, endCut = %d", startCut, endCut) } - return fmt.Errorf("internal error: failed to find cut points: startCut = %d, endCut = %d", startCut, endCut) + } else { + var out strings.Builder + if groupsString := cmd.Annotations["groups"]; groupsString != "" { + groups := flags.All.Include(groupsString) + for _, group := range groups.Groups { + if group.Flags.HasFlags() { + _, _ = fmt.Fprintf(&out, "\n### %s Options\n\n", group.Name) + _, _ = fmt.Fprintf(&out, "%s\n\n", group.Help) + _, _ = fmt.Fprintln(&out, "```") + _, _ = out.WriteString(group.Flags.FlagUsages()) + _, _ = fmt.Fprintln(&out, "```") + } + } + } + _, _ = out.WriteString(` +See the [global flags page](/flags/) for global options not listed here. + +`) + doc = doc[:startCut] + out.String() + doc[endCut:] } - doc = doc[:startCut] + out.String() + doc[endCut:] + // outdent all the titles by one doc = outdentTitle.ReplaceAllString(doc, `$1`) err = os.WriteFile(path, []byte(doc), 0777)