#!/bin/bash

VERSION=$1

rm -rf go-md2man-*.tar.?z go-modules-go-md2man*

echo "Downloading go-md2man-$VERSION..."

wget "https://github.com/cpuguy83/go-md2man/archive/v$VERSION/go-md2man-$VERSION.tar.gz"

tar xf go-md2man-$VERSION.tar.gz
mkdir -p go-modules-go-md2man-$VERSION

cd go-md2man-$VERSION
  export GOPATH=$(realpath ../go-modules-go-md2man-$VERSION)
  go mod download
cd ..

cd go-modules-go-md2man-$VERSION/pkg/mod/cache/
  mv download go-modules-go-md2man-$VERSION
  tar cf ../../../../go-modules-go-md2man-$VERSION.tar go-modules-go-md2man-$VERSION
cd ../../../../

plzip -9 go-modules-go-md2man-$VERSION.tar

gunzip go-md2man-$VERSION.tar.gz
plzip -9 go-md2man-$VERSION.tar

rm -rf go-md2man-$VERSION
rm -rf go-modules-go-md2man-$VERSION
