github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/scripts/docs/generate-man.sh (about) 1 #!/usr/bin/env bash 2 3 set -eu 4 5 : "${MD2MAN_VERSION=v2.0.3}" 6 7 export GO111MODULE=auto 8 9 function clean { 10 rm -rf "$buildir" 11 } 12 13 buildir=$(mktemp -d -t docker-cli-docsgen.XXXXXXXXXX) 14 trap clean EXIT 15 16 ( 17 set -x 18 cp -r . "$buildir/" 19 cd "$buildir" 20 # init dummy go.mod 21 ./scripts/vendor init 22 # install go-md2man and copy man/tools.go in root folder 23 # to be able to fetch the required dependencies 24 go mod edit -modfile=vendor.mod -require=github.com/cpuguy83/go-md2man/v2@${MD2MAN_VERSION} 25 cp man/tools.go . 26 # update vendor 27 ./scripts/vendor update 28 # build gen-manpages 29 go build -mod=vendor -modfile=vendor.mod -tags manpages -o /tmp/gen-manpages ./man/generate.go 30 # build go-md2man 31 go build -mod=vendor -modfile=vendor.mod -o /tmp/go-md2man ./vendor/github.com/cpuguy83/go-md2man/v2 32 ) 33 34 mkdir -p man/man1 35 (set -x ; /tmp/gen-manpages --root "." --target "$(pwd)/man/man1") 36 37 ( 38 cd man 39 for FILE in *.md; do 40 base="$(basename "$FILE")" 41 name="${base%.md}" 42 num="${name##*.}" 43 if [ -z "$num" ] || [ "$name" = "$num" ]; then 44 # skip files that aren't of the format xxxx.N.md (like README.md) 45 continue 46 fi 47 mkdir -p "./man${num}" 48 (set -x ; /tmp/go-md2man -in "$FILE" -out "./man${num}/${name}") 49 done 50 )