Skip to content

Commit

Permalink
Generate docs/commands.md based on CLI help
Browse files Browse the repository at this point in the history
This will significantly simplify the process of documentation updates.
Also, there is configured verification step which checks if
documentation is re-generated for fresh changes. This will guarantee
that we always will have up-to-date documentation for the commands
(most updated file).

#118
  • Loading branch information
extsoft committed Sep 11, 2019
1 parent 98a0ed8 commit 449668e
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 90 deletions.
65 changes: 65 additions & 0 deletions .wf/docs-generation.bash
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

export PATH=bin:${PATH}
if [[ ! $(ls -l README.md) ]]; then
echo "Please run this script from the root of the repo."
echo "Current path: ${PWD}"
exit 1
fi

header() {
echo "# \`${1}\`"
}

report-command() {
header ${1} >> ${2}
eval "git-elegant ${1} --help" >> ${2}
}

report-commands() {
echo "Write all commands to '${1}'"
for command in $(git-elegant commands); do
report-command ${command} ${1}
done
}

escape-usage() {
local TMPFILE="TMPFILE"
local usage=""
local IFS=''
while read -r; do
if [[ ${REPLY} == usage* ]]; then
usage="found"
fi
if [[ ${usage} == "found" ]]; then
echo "\`\`\`bash" >> ${TMPFILE}
usage="close"
fi
if [[ -z ${REPLY} && ${usage} == "close" ]]; then
echo "\`\`\`" >> ${TMPFILE}
usage=""
fi
echo -e ${REPLY} >> ${TMPFILE}
done < ${1}
echo "Replace escaped file with original: '${TMPFILE}' > '${1}' "
rm -v ${1}
mv -v ${TMPFILE} ${1}
}


main() {
local final="docs/commands.md"
local commands="docs/raw-commands.md"
report-commands ${commands}
escape-usage ${commands}

echo "Craft '${final}' file from '${commands}'"
header git-elegant > ${final}
echo "\`\`\`bash" >> ${final}
git-elegant >> ${final}
echo -e "\`\`\`\n" >> ${final}
cat ${commands} | sed -e '$ d' >> ${final}
rm -v ${commands}
}

main
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -54,7 +54,7 @@ something which should be quickly available, please propose changes here.
- [Writing tests](#writing-tests)
- [Assertions](#assertions)
- [Test name template](#test-name-template)
- [Documentation preview](#documentation-preview)
- [Updating documentation](#updating-documentation)

### Architecture

Expand Down Expand Up @@ -131,7 +131,10 @@ Also, there are several optional addons which can be useful in some circumstance
Use the following test name template - `'<command args>': <describe what will be tested>` like
`'clone-repository': raise an error if cloneable URL isn't set`.

### Documentation preview
### Updating documentation
In order to get the documentation preview locally, please install required dependencies with
`pip install -r docs/requirements.txt`. After, run `mkdocs serve` and open <http://127.0.0.1:8000/>
in a browser. That's it!

The [docs/commands.md](docs/commands.md) generates by running `./.wf/docs-generation.bash` script.
All other files in ["docs" directory](docs/) require manual corrections.

1 comment on commit 449668e

@0pdd
Copy link

@0pdd 0pdd commented on 449668e Sep 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 6-8bd69a57 disappeared from src/main/git-elegant, that's why I closed #118. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.