From d74662a751912858d3306e0bc6bb1bd1ad683543 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 25 Nov 2022 23:41:23 +0100 Subject: [PATCH] docs: add badge showing version introduced and experimental/beta/deprecated status to command doc pages --- cmd/gendocs/gendocs.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/gendocs/gendocs.go b/cmd/gendocs/gendocs.go index 4965aa7a3..4c5417abc 100644 --- a/cmd/gendocs/gendocs.go +++ b/cmd/gendocs/gendocs.go @@ -31,6 +31,7 @@ type frontmatter struct { Slug string URL string Source string + Annotations map[string]string } var frontmatterTemplate = template.Must(template.New("frontmatter").Parse(`--- @@ -38,6 +39,9 @@ title: "{{ .Title }}" description: "{{ .Description }}" slug: {{ .Slug }} url: {{ .URL }} +{{- range $key, $value := .Annotations }} +{{ $key }}: {{ $value }} +{{- end }} # autogenerated - DO NOT EDIT, instead edit the source code in {{ .Source }} and as part of making a release run "make commanddocs" --- `)) @@ -75,17 +79,24 @@ rclone.org website.`, return err } - // Look up name => description for prepender - var description = map[string]string{} - var addDescription func(root *cobra.Command) - addDescription = func(root *cobra.Command) { + // Look up name => details for prepender + type commandDetails struct { + Short string + Annotations map[string]string + } + var commands = map[string]commandDetails{} + var addCommandDetails func(root *cobra.Command) + addCommandDetails = func(root *cobra.Command) { name := strings.ReplaceAll(root.CommandPath(), " ", "_") + ".md" - description[name] = root.Short + commands[name] = commandDetails{ + Short: root.Short, + Annotations: root.Annotations, + } for _, c := range root.Commands() { - addDescription(c) + addCommandDetails(c) } } - addDescription(cmd.Root) + addCommandDetails(cmd.Root) // markup for the docs files prepender := func(filename string) string { @@ -94,10 +105,11 @@ rclone.org website.`, data := frontmatter{ Date: now, Title: strings.ReplaceAll(base, "_", " "), - Description: description[name], + Description: commands[name].Short, Slug: base, URL: "/commands/" + strings.ToLower(base) + "/", Source: strings.ReplaceAll(strings.ReplaceAll(base, "rclone", "cmd"), "_", "/") + "/", + Annotations: commands[name].Annotations, } var buf bytes.Buffer err := frontmatterTemplate.Execute(&buf, data)