Browse code

Add a script to generate man pages from cobra commands.

Use the generate.sh script instead of md2man directly.
Update Dockerfile for generating man pages.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/06/10 00:33:28
Showing 11 changed files
... ...
@@ -126,6 +126,12 @@ test-unit: build ## run the unit tests
126 126
 validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor 
127 127
 	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-default-seccomp validate-gofmt validate-pkg validate-lint validate-test validate-toml validate-vet validate-vendor
128 128
 
129
+manpages: ## Generate man pages from go source and markdown
130
+	docker build -t docker-manpage-dev -f man/Dockerfile .
131
+	docker run \
132
+		-v $(PWD):/go/src/github.com/docker/docker/ \
133
+		docker-manpage-dev
134
+
129 135
 help: ## this help
130 136
 	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
131 137
 
... ...
@@ -33,6 +33,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
33 33
 
34 34
 	var rootCmd = &cobra.Command{
35 35
 		Use:           "docker [OPTIONS]",
36
+		Short:         "A self-sufficient runtime for containers",
36 37
 		SilenceUsage:  true,
37 38
 		SilenceErrors: true,
38 39
 	}
... ...
@@ -131,9 +132,15 @@ func (c CobraAdaptor) Command(name string) func(...string) error {
131 131
 	return nil
132 132
 }
133 133
 
134
+// GetRootCommand returns the root command. Required to generate the man pages
135
+// and reference docs from a script outside this package.
136
+func (c CobraAdaptor) GetRootCommand() *cobra.Command {
137
+	return c.rootCmd
138
+}
139
+
134 140
 var usageTemplate = `Usage:	{{if not .HasSubCommands}}{{.UseLine}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
135 141
 
136
-{{with or .Long .Short }}{{. | trim}}{{end}}{{if gt .Aliases 0}}
142
+{{ .Short | trim }}{{if gt .Aliases 0}}
137 143
 
138 144
 Aliases:
139 145
   {{.NameAndAliases}}{{end}}{{if .HasExample}}
... ...
@@ -35,7 +35,7 @@ set -e
35 35
 	debDate="$(date --rfc-2822)"
36 36
 
37 37
 	# if go-md2man is available, pre-generate the man pages
38
-	./man/md2man-all.sh -q || true
38
+	./man/generate.sh || true
39 39
 	# TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this
40 40
 
41 41
 	builderDir="contrib/builder/deb/${PACKAGE_ARCH}"
... ...
@@ -51,7 +51,7 @@ set -e
51 51
 	rpmDate="$(date +'%a %b %d %Y')"
52 52
 
53 53
 	# if go-md2man is available, pre-generate the man pages
54
-	./man/md2man-all.sh -q || true
54
+	./man/generate.sh || true
55 55
 	# TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this
56 56
 
57 57
 	# Convert the CHANGELOG.md file into RPM changelog format
... ...
@@ -59,8 +59,8 @@ bundle_ubuntu() {
59 59
 	mkdir -p "$DIR/etc/fish/completions"
60 60
 	cp contrib/completion/fish/docker.fish "$DIR/etc/fish/completions/"
61 61
 
62
-	# Include contributed man pages
63
-	man/md2man-all.sh -q
62
+	# Include man pages
63
+	man/generate.sh
64 64
 	manRoot="$DIR/usr/share/man"
65 65
 	mkdir -p "$manRoot"
66 66
 	for manDir in man/man?; do
... ...
@@ -1,7 +1,20 @@
1
-FROM golang:1.6.3
2
-RUN mkdir -p /go/src/github.com/cpuguy83
3
-RUN mkdir -p /go/src/github.com/cpuguy83 \
4
-    && git clone -b v1.0.5 https://github.com/cpuguy83/go-md2man.git /go/src/github.com/cpuguy83/go-md2man \
5
-    && cd /go/src/github.com/cpuguy83/go-md2man \
6
-    && go get -v ./...
7
-CMD ["/go/bin/go-md2man", "--help"]
1
+FROM    golang:1.6.3-alpine
2
+
3
+RUN     apk add -U git bash curl gcc musl-dev
4
+
5
+RUN     export GLIDE=0.10.2; \
6
+        export SRC=https://github.com/Masterminds/glide/releases/download/; \
7
+        curl -sL ${SRC}/${GLIDE}/glide-${GLIDE}-linux-amd64.tar.gz | \
8
+        tar -xz linux-amd64/glide && \
9
+        mv linux-amd64/glide /usr/bin/glide && \
10
+        chmod +x /usr/bin/glide
11
+
12
+COPY    man/glide.yaml /manvendor/
13
+COPY    man/glide.lock /manvendor/
14
+WORKDIR /manvendor/
15
+RUN     glide install && mv vendor src
16
+ENV     GOPATH=$GOPATH:/go/src/github.com/docker/docker/vendor:/manvendor
17
+RUN     go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man
18
+
19
+WORKDIR /go/src/github.com/docker/docker/
20
+ENTRYPOINT ["man/generate.sh"]
... ...
@@ -1,33 +1,15 @@
1 1
 Docker Documentation
2 2
 ====================
3 3
 
4
-This directory contains the Docker user manual in the Markdown format.
5
-Do *not* edit the man pages in the man1 directory. Instead, amend the
6
-Markdown (*.md) files.
4
+This directory contains scripts for generating the man pages. Many of the man
5
+pages are generated directly from the `spf13/cobra` `Command` definition. Some
6
+legacy pages are still generated from the markdown files in this directory.
7
+Do *not* edit the man pages in the man1 directory. Instead, update the
8
+Cobra command or amend the Markdown files for legacy pages.
7 9
 
8
-# Generating man pages from the Markdown files
9 10
 
10
-The recommended approach for generating the man pages is via a Docker
11
-container using the supplied `Dockerfile` to create an image with the correct
12
-environment. This uses `go-md2man`, a pure Go Markdown to man page generator.
11
+## Generate the mange pages
13 12
 
14
-## Building the md2man image
13
+From within the project root directory run:
15 14
 
16
-There is a `Dockerfile` provided in the `/man` directory of your
17
-'docker/docker' fork.
18
-
19
-Using this `Dockerfile`, create a Docker image tagged `docker/md2man`:
20
-
21
-    docker build -t docker/md2man .
22
-
23
-## Utilizing the image
24
-
25
-From within the `/man` directory run the following command:
26
-
27
-    docker run -v $(pwd):/man -w /man -i docker/md2man ./md2man-all.sh
28
-    
29
-The `md2man` Docker container will process the Markdown files and generate
30
-the man pages inside the `/man/man1` directory of your fork using
31
-Docker volumes. For more information on Docker volumes see the man page for
32
-`docker run` and also look at the article [Sharing Directories via Volumes]
33
-(https://docs.docker.com/use/working_with_volumes/).
15
+    make manpages
34 16
new file mode 100644
... ...
@@ -0,0 +1,39 @@
0
+package main
1
+
2
+import (
3
+	"fmt"
4
+	"os"
5
+
6
+	"github.com/docker/docker/cli/cobraadaptor"
7
+	cliflags "github.com/docker/docker/cli/flags"
8
+	"github.com/spf13/cobra/doc"
9
+)
10
+
11
+func generateManPages(path string) error {
12
+	header := &doc.GenManHeader{
13
+		Title:   "DOCKER",
14
+		Section: "1",
15
+		Source:  "Docker Community",
16
+	}
17
+	flags := &cliflags.ClientFlags{
18
+		Common: cliflags.InitCommonFlags(),
19
+	}
20
+	cmd := cobraadaptor.NewCobraAdaptor(flags).GetRootCommand()
21
+	cmd.DisableAutoGenTag = true
22
+	return doc.GenManTreeFromOpts(cmd, doc.GenManTreeOptions{
23
+		Header:           header,
24
+		Path:             path,
25
+		CommandSeparator: "-",
26
+	})
27
+}
28
+
29
+func main() {
30
+	path := "/tmp"
31
+	if len(os.Args) > 1 {
32
+		path = os.Args[1]
33
+	}
34
+	fmt.Printf("Generating man pages into %s\n", path)
35
+	if err := generateManPages(path); err != nil {
36
+		fmt.Fprintf(os.Stderr, "Failed to generate man pages: %s\n", err.Error())
37
+	}
38
+}
0 39
new file mode 100755
... ...
@@ -0,0 +1,15 @@
0
+#!/bin/bash
1
+#
2
+# Generate man pages for docker/docker
3
+#
4
+
5
+set -eu
6
+
7
+mkdir -p ./man/man1
8
+
9
+# Generate man pages from cobra commands
10
+go build -o /tmp/gen-manpages ./man
11
+/tmp/gen-manpages ./man/man1
12
+
13
+# Generate legacy pages from markdown
14
+./man/md2man-all.sh -q
0 15
new file mode 100644
... ...
@@ -0,0 +1,52 @@
0
+hash: ead3ea293a6143fe41069ebec814bf197d8c43a92cc7666b1f7e21a419b46feb
1
+updated: 2016-06-20T21:53:35.420817456Z
2
+imports:
3
+- name: github.com/BurntSushi/toml
4
+  version: f0aeabca5a127c4078abb8c8d64298b147264b55
5
+- name: github.com/cpuguy83/go-md2man
6
+  version: 2724a9c9051aa62e9cca11304e7dd518e9e41599
7
+  subpackages:
8
+  - md2man
9
+- name: github.com/fsnotify/fsnotify
10
+  version: 30411dbcefb7a1da7e84f75530ad3abe4011b4f8
11
+- name: github.com/hashicorp/hcl
12
+  version: da486364306ed66c218be9b7953e19173447c18b
13
+  subpackages:
14
+  - hcl/ast
15
+  - hcl/parser
16
+  - hcl/token
17
+  - json/parser
18
+  - hcl/scanner
19
+  - hcl/strconv
20
+  - json/scanner
21
+  - json/token
22
+- name: github.com/inconshreveable/mousetrap
23
+  version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
24
+- name: github.com/magiconair/properties
25
+  version: c265cfa48dda6474e208715ca93e987829f572f8
26
+- name: github.com/mitchellh/mapstructure
27
+  version: d2dd0262208475919e1a362f675cfc0e7c10e905
28
+- name: github.com/russross/blackfriday
29
+  version: 1d6b8e9301e720b08a8938b8c25c018285885438
30
+- name: github.com/shurcooL/sanitized_anchor_name
31
+  version: 10ef21a441db47d8b13ebcc5fd2310f636973c77
32
+- name: github.com/spf13/cast
33
+  version: 27b586b42e29bec072fe7379259cc719e1289da6
34
+- name: github.com/spf13/jwalterweatherman
35
+  version: 33c24e77fb80341fe7130ee7c594256ff08ccc46
36
+- name: github.com/spf13/pflag
37
+  version: 367864438f1b1a3c7db4da06a2f55b144e6784e0
38
+- name: github.com/spf13/viper
39
+  version: c1ccc378a054ea8d4e38d8c67f6938d4760b53dd
40
+- name: golang.org/x/sys
41
+  version: 62bee037599929a6e9146f29d10dd5208c43507d
42
+  subpackages:
43
+  - unix
44
+- name: gopkg.in/yaml.v2
45
+  version: a83829b6f1293c91addabc89d0571c246397bbf4
46
+- name: github.com/spf13/cobra
47
+  repo: https://github.com/dnephin/cobra
48
+  subpackages:
49
+  - doc
50
+  version: dc45219961f875acff5ee07ed263e5dc19e0c5f1
51
+devImports: []
0 52
new file mode 100644
... ...
@@ -0,0 +1,12 @@
0
+package: github.com/docker/docker/man
1
+import:
2
+- package: github.com/cpuguy83/go-md2man
3
+  subpackages:
4
+  - md2man
5
+- package: github.com/inconshreveable/mousetrap
6
+- package: github.com/spf13/pflag
7
+- package: github.com/spf13/viper
8
+- package: github.com/spf13/cobra
9
+  repo: https://github.com/dnephin/cobra
10
+  subpackages:
11
+  - doc