#!/bin/sh

set -e

GOVERSION=1.27

# Section 1
list="build clean env fix fmt get install list mod run test tool version vet"
for cmd in $list; do
    help2man \
    --section=1 \
    --no-discard-stderr \
    --no-info \
    --version-string "$GOVERSION" \
    -h "help $cmd" \
    /usr/lib/go-$GOVERSION/bin/go | \
    pandoc -f man -t markdown -s -o "raw/$cmd.md"
    sed -i -e "s/go 1.[0-9]\+/go 1.XX/g" "raw/$cmd.md"
done

# Special cases
list="go gofmt"
for cmd in $list; do
    help2man \
    --section=1 \
    --no-discard-stderr \
    --no-info \
    --version-string "$GOVERSION" \
    /usr/lib/go-$GOVERSION/bin/$cmd | \
    pandoc -f man -t markdown -s -o "raw/$cmd.md"
    sed -i -e "s/go 1.[0-9]\+/go 1.XX/g" "raw/$cmd.md"
done

# Section 7
list="packages testflag testfunc"
for cmd in $list; do
    help2man \
    --section=7 \
    --no-discard-stderr \
    --no-info \
    --version-string "$GOVERSION" \
    -h "help $cmd" \
    /usr/lib/go-$GOVERSION/bin/go | \
    pandoc -f man -t markdown -s -o "raw/$cmd.md"
    sed -i -e "s/go 1.[0-9]\+/go 1.XX/g" "raw/$cmd.md"
done
