Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate man pages for kuma components #2101

Merged
merged 4 commits into from Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mk/docs.mk
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
@@ -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