Skip to content

Commit

Permalink
docs(*) generate man pages for kuma components (#2101)
Browse files Browse the repository at this point in the history
Update docs make file with man pages generation.

Signed-off-by: Tharun <rajendrantharun@live.com>
  • Loading branch information
tharun208 authored Jun 24, 2021
1 parent e2bd183 commit 06236c6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docs/install/markdown: ## Generate CLI reference in markdown format
.PHONY: docs/install/manpages
docs/install/manpages: DESTDIR ?= docs/manpages
docs/install/manpages: ## Generate CLI reference in man(1) format
@echo target $@ not implemented
@DESTDIR=$(DESTDIR) FORMAT=man $(GO_RUN) ./tools/docs/generate.go

.PHONY: docs/install/protobuf
docs/install/protobuf: DESTDIR ?= docs/protobuf
Expand Down
60 changes: 54 additions & 6 deletions tools/docs/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"
"path"
Expand All @@ -12,6 +13,7 @@ import (
kuma_dp "github.com/kumahq/kuma/app/kuma-dp/cmd"
kuma_prometheus_sd "github.com/kumahq/kuma/app/kuma-prometheus-sd/cmd"
kumactl "github.com/kumahq/kuma/app/kumactl/cmd"
"github.com/kumahq/kuma/pkg/version"
)

// GetenvOr returns the value of the environment variable named by env,
Expand Down Expand Up @@ -49,21 +51,67 @@ func markdown(path string, cmd *cobra.Command) {
must(doc.GenMarkdownTree(cmd, path))
}

func man(path string, header *doc.GenManHeader, cmd *cobra.Command) {
must(os.MkdirAll(path, 0755))
must(doc.GenManTree(cmd, header, path))
}

type command struct {
command *cobra.Command
header *doc.GenManHeader
}

func main() {
prefix := GetenvOr("DESTDIR", ".")
format := GetenvOr("FORMAT", "markdown")

apps := map[string]*cobra.Command{
path.Join(prefix, "kuma-cp"): kuma_cp.DefaultRootCmd(),
path.Join(prefix, "kumactl"): kumactl.DefaultRootCmd(),
path.Join(prefix, "kuma-dp"): kuma_dp.DefaultRootCmd(),
path.Join(prefix, "kuma-prometheus-sd"): kuma_prometheus_sd.DefaultRootCmd(),
apps := map[string]command{
path.Join(prefix, "kuma-cp"): command{
command: kuma_cp.DefaultRootCmd(),
header: &doc.GenManHeader{
Title: "KUMA-CP",
Section: "8",
Source: fmt.Sprintf("%s %s", version.Product, version.Build.Version),
Manual: version.Product,
},
},
path.Join(prefix, "kuma-dp"): command{
command: kuma_dp.DefaultRootCmd(),
header: &doc.GenManHeader{
Title: "KUMA-DP",
Section: "8",
Source: fmt.Sprintf("%s %s", version.Product, version.Build.Version),
Manual: version.Product,
},
},
path.Join(prefix, "kuma-prometheus-sd"): command{
command: kuma_prometheus_sd.DefaultRootCmd(),
header: &doc.GenManHeader{
Title: "KUMA-PROMETHEUS-SD",
Section: "8",
Source: fmt.Sprintf("%s %s", version.Product, version.Build.Version),
Manual: version.Product,
},
},
path.Join(prefix, "kumactl"): command{
command: kumactl.DefaultRootCmd(),
header: &doc.GenManHeader{
Title: "KUMACTL",
Section: "1",
Source: fmt.Sprintf("%s %s", version.Product, version.Build.Version),
Manual: version.Product,
},
},
}

switch format {
case "markdown":
for p, c := range apps {
markdown(p, disableAutogen(c))
markdown(p, disableAutogen(c.command))
}
case "man":
for p, c := range apps {
man(p, c.header, disableAutogen(c.command))
}
default:
log.Fatalf("unsupported reference format %q", format)
Expand Down

0 comments on commit 06236c6

Please sign in to comment.