Generates documentation from code comments automatically
go get github.com/gominima/docgen
go run github.com/gominima/docgen
Name | Position | Description | Default |
---|---|---|---|
path | 1 | The directory which contains the docgen files | . The current directory |
outputfile | 2 | The name of the output JSON file | output.json |
Gominima/Docgen does not utilises flags because there are only 2 arguments and if you skip the first one .
and write the second one, even as, -O main.json
thats still a character more than just writing . main.json
You can also automate the documentation generation by using a workflow which pushes to a seprate repository
Here is an example of the workflow we use in minima repository:
name: Generate Documentation
on:
push:
branches:
- "main"
- "stable"
jobs:
docs:
name: Generate Docs
runs-on: ubuntu-latest
if: github.repository_owner == 'gominima'
outputs:
REPO_NAME: ${{ steps.env.outputs.REPO_NAME }}
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
SHA: ${{ steps.env.outputs.SHA }}
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: 1.17
- name: Get docgen
run: go get github.com/gominima/docgen
- name: Run docgen
run: go run github.com/gominima/docgen . $(basename `git rev-parse --show-toplevel`)-$(git rev-parse --abbrev-ref HEAD).json
- name: Checkout docs repository
uses: actions/checkout@v2
with:
repository: 'gominima/docs'
token: ${{ secrets.API_TOKEN_GITHUB }}
path: 'out'
- name: Commit and push
run: |
mv $(basename `git rev-parse --show-toplevel`)-$(git rev-parse --abbrev-ref HEAD).json out
cd out
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git add .
git commit -m "Docs build for ${GITHUB_REF_TYPE} ${GITHUB_REF_NAME}: ${GITHUB_SHA}" || true
git push
The docgen format is heavily inspired from the JSDoc format, it however does not completely support the JSDoc specification and is NOT a replacement for JavaScript documentation generators
@info
tag to addDescription
in JSON@param {type} [name] optional description
to add a value to theParameters
array section@returns {type} optional description
to addReturns
value in JSON
/**
* @info function description
* @param {string} [example] param description
* @returns {int}
*/
func someFunc(example string) int {
return 1;
}
@info
tag to addDescription
in JSON@property {type} [name] optional description
to add a value to theProperties
array section- Functions on Structures are automatically added to
Functions
array section inside the Structure if they have comments
/**
* @info structure description
* @property {string} [example] property description
*/
type example struct {
example string
}