Skip to content

Instantly share code, notes, and snippets.

@cokert
Last active January 17, 2020 22:34
Show Gist options
  • Save cokert/7b952b73849c4c3d6e71ce2f0aaa1444 to your computer and use it in GitHub Desktop.
Save cokert/7b952b73849c4c3d6e71ce2f0aaa1444 to your computer and use it in GitHub Desktop.
Generate GO documentation
#note this depends on having the script at the gist below available by calling relapth.sh
#https://gist.github.com/cokert/089100625c6ebed2d10650b223cb7ca4
if [ -z $1 ]
then
echo "destination not supplied"
exit 1
fi
SRC=${PWD}
DOCPATH=$1
#purge and recreate destination
rm -rf $DOCPATH
mkdir $DOCPATH
#generate docs (ignoring directories git and cmd)
find $SRC -not -path '*/\.git*' -not -path '*/cmd/*' -type d | xargs -I % sh -c 'relpath.sh '$SRC' %' | xargs -I % sh -c 'mkdir '$DOCPATH'/%; go doc -all ./% > '$DOCPATH'/%.txt'
#remove empty files/directories
find $DOCPATH -empty -delete
@cokert
Copy link
Author

cokert commented Jan 17, 2020

if you try to execute in a folder where there is a package is in the root folder (like this: https://github.com/turnerlabs/cstore), that root package will be missed. and if you're looking at a repo where there are no folders (the package is the top level folder like this: https://github.com/juju/errors) it will output nothing. and complain about a relative find -delete

in the second case, you can (obviously) just run go doc -all > <dest>/<filename>.txt manually...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment