Skip to content

Commit

Permalink
validate manpages target
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 25, 2022
1 parent a650f4d commit 7dc35c0
Show file tree
Hide file tree
Showing 50 changed files with 88 additions and 10,065 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/cli/winresources/versioninfo.json
/cli/winresources/*.syso
/man/man*/
/man/vendor/
/man/go.sum
/docs/yaml/
/docs/vendor/
/docs/go.sum
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
matrix:
target:
- yamldocs # ensure yamldocs target runs fine
- manpages # ensure manpages target runs fine
steps:
-
name: Checkout
Expand All @@ -48,5 +49,6 @@ jobs:
fetch-depth: 0
-
name: Run
shell: 'script --return --quiet --command "bash {0}"'
run: |
make -f docker.Makefile ${{ matrix.target }}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Thumbs.db
/build/
/cli/winresources/versioninfo.json
/cli/winresources/*.syso
/man/man1/
/man/man5/
/man/man8/
profile.out

# top-level go.mod is not meant to be checked in
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS))

.PHONY: clean
clean: ## remove build artifacts
rm -rf ./build/* cli/winresources/rsrc_* ./man/man[1-9] docs/yaml
rm -rf ./build/* man/man[1-9] docs/yaml

.PHONY: test
test: test-unit ## run tests
Expand Down
3 changes: 3 additions & 0 deletions man/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/man*
/go.sum
4 changes: 3 additions & 1 deletion man/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Cobra command or amend the Markdown files for legacy pages.

From within the project root directory run:

make manpages
```shell
$ make -f docker.Makefile manpages
```
7 changes: 7 additions & 0 deletions man/generate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This file is intended for use with "go run"; it isn't really part of the package.

// +build manpages

package main

import (
Expand All @@ -18,6 +22,8 @@ import (
const descriptionSourcePath = "man/src/"

func generateManPages(opts *options) error {
log.SetFlags(0)

header := &doc.GenManHeader{
Title: "DOCKER",
Section: "1",
Expand Down Expand Up @@ -73,6 +79,7 @@ func loadLongDescription(cmd *cobra.Command, path string) error {
continue
}

log.Printf("INFO: %s found\n", fullpath)
content, err := os.ReadFile(fullpath)
if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions man/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/docker/cli/man

// dummy go.mod to avoid dealing with dependencies specific
// to manpages generation and not really part of the project.

go 1.16

//require (
// github.com/docker/cli v0.0.0+incompatible
// github.com/cpuguy83/go-md2man/v2 v2.0.1
// github.com/spf13/cobra v1.2.1
// github.com/spf13/pflag v1.0.5
//)
//
//replace github.com/docker/cli v0.0.0+incompatible => ../
7 changes: 0 additions & 7 deletions man/import.go

This file was deleted.

22 changes: 0 additions & 22 deletions man/md2man-all.sh

This file was deleted.

10 changes: 10 additions & 0 deletions man/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build tools

package main

import (
_ "github.com/cpuguy83/go-md2man/v2"
_ "github.com/spf13/cobra"
_ "github.com/spf13/cobra/doc"
_ "github.com/spf13/pflag"
)
57 changes: 45 additions & 12 deletions scripts/docs/generate-man.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
#!/usr/bin/env bash
# Generate man pages for docker/cli
set -eu -o pipefail

mkdir -p ./man/man1
set -eu

if ! command -v go-md2man &> /dev/null; then
# yay, go install creates a binary named "v2" ¯\_(ツ)_/¯
go build -o "/go/bin/go-md2man" ./vendor/github.com/cpuguy83/go-md2man/v2
fi
: "${MD2MAN_VERSION=v2.0.1}"

# Generate man pages from cobra commands
go build -o /tmp/gen-manpages github.com/docker/cli/man
/tmp/gen-manpages --root "$(pwd)" --target "$(pwd)/man/man1"
export GO111MODULE=auto

# Generate legacy pages from markdown
./man/md2man-all.sh -q
function clean {
rm -rf "$buildir"
}

buildir=$(mktemp -d -t docker-cli-docsgen.XXXXXXXXXX)
trap clean EXIT

(
set -x
cp -r . "$buildir/"
cd "$buildir"
# init dummy go.mod
./scripts/vendor init
# install go-md2man and copy man/tools.go in root folder
# to be able to fetch the required dependencies
go mod edit -modfile=vendor.mod -require=github.com/cpuguy83/go-md2man/v2@${MD2MAN_VERSION}
cp man/tools.go .
# update vendor
./scripts/vendor update
# build gen-manpages
go build -mod=vendor -modfile=vendor.mod -tags manpages -o /tmp/gen-manpages ./man/generate.go
# build go-md2man
go build -mod=vendor -modfile=vendor.mod -o /tmp/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
)

mkdir -p man/man1
(set -x ; /tmp/gen-manpages --root "." --target "$(pwd)/man/man1")

(
cd man
for FILE in *.md; do
base="$(basename "$FILE")"
name="${base%.md}"
num="${name##*.}"
if [ -z "$num" ] || [ "$name" = "$num" ]; then
# skip files that aren't of the format xxxx.N.md (like README.md)
continue
fi
mkdir -p "./man${num}"
(set -x ; /tmp/go-md2man -in "$FILE" -out "./man${num}/${name}")
done
)
1 change: 0 additions & 1 deletion vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/Microsoft/go-winio v0.4.19 // indirect
github.com/containerd/containerd v1.5.5
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1
github.com/creack/pty v1.1.11
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v20.10.7+incompatible
Expand Down
4 changes: 0 additions & 4 deletions vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
Expand Down Expand Up @@ -555,8 +553,6 @@ github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
Expand Down
2 changes: 0 additions & 2 deletions vendor/github.com/cpuguy83/go-md2man/v2/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/cpuguy83/go-md2man/v2/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/cpuguy83/go-md2man/v2/LICENSE.md

This file was deleted.

35 changes: 0 additions & 35 deletions vendor/github.com/cpuguy83/go-md2man/v2/Makefile

This file was deleted.

15 changes: 0 additions & 15 deletions vendor/github.com/cpuguy83/go-md2man/v2/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/cpuguy83/go-md2man/v2/go-md2man.1.md

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/cpuguy83/go-md2man/v2/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/cpuguy83/go-md2man/v2/go.sum

This file was deleted.

51 changes: 0 additions & 51 deletions vendor/github.com/cpuguy83/go-md2man/v2/md2man.go

This file was deleted.

0 comments on commit 7dc35c0

Please sign in to comment.