Files
docker-cli/scripts/docs/generate-man.sh
Sebastiaan van Stijn 535bb6c85c rewrite using "with-go-mod.sh" script and "go run"
Use the same script as is used in moby/moby, which more gracefully
handles an existing `go.mod` (which can be symlinked) into account.

- keep the scripts called generic, and update the Makefile to invoke
  them with the "with-go-mod.sh" script.
- use "go run" instead of building temporary binaries
- check if go-md2man exists before building a binary

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-21 00:36:47 +01:00

38 lines
806 B
Bash
Executable File

#!/usr/bin/env bash
set -eu
: "${GO_MD2MAN:=go-md2man}"
if ! command -v "$GO_MD2MAN" > /dev/null; then
(
set -x
go build -mod=vendor -modfile=vendor.mod -o ./build/tools/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2
)
GO_MD2MAN=$(realpath ./build/tools/go-md2man)
fi
mkdir -p man/man1
(
set -x
go run -mod=vendor -modfile=vendor.mod -tags manpages ./man/generate.go --root "." --target "./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 ;
"$GO_MD2MAN" -in "$FILE" -out "./man${num}/${name}"
)
done
)