-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate docs/commands.md based on CLI help
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
Showing
4 changed files
with
249 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
449668e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
6-8bd69a57
disappeared fromsrc/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.