Yegor Timoshenko | c2e4941 | 2018-10-07 01:58:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Tom Hiller | ed6d1e6 | 2018-07-21 00:23:17 -0400 | [diff] [blame] | 2 | |
| 3 | # Creates `./util/README.md` and `./Documentation/Util.md` of description files |
| 4 | # in `./util` subdirectories |
| 5 | # |
| 6 | # Execute from root of project. Example: |
Jonathan Neuschäfer | 05400b7 | 2018-12-11 15:49:04 +0100 | [diff] [blame] | 7 | # `util/util_readme/util_readme.sh` |
Tom Hiller | ed6d1e6 | 2018-07-21 00:23:17 -0400 | [diff] [blame] | 8 | |
| 9 | UTIL_README_DIR="$(cd "$(dirname "$0")" || exit; pwd -P)" |
| 10 | UTIL_DIR=$(dirname "$UTIL_README_DIR") |
| 11 | COREBOOT_ROOT_DIR=$(dirname "$UTIL_DIR") |
| 12 | DOCMENTATION_DIR="$COREBOOT_ROOT_DIR/Documentation" |
Tom Hiller | 785dee0 | 2018-07-26 21:33:35 -0400 | [diff] [blame] | 13 | SUMMARY="_Scripts and programs found in the \`./util\` directory_" |
Tom Hiller | ed6d1e6 | 2018-07-21 00:23:17 -0400 | [diff] [blame] | 14 | |
| 15 | DESCRIPTION_FILES=$(find "$UTIL_DIR" -name "description.md" | sort) |
| 16 | |
| 17 | echo -n "" > "$UTIL_DIR/README.md" |
| 18 | echo "# Utilities" > "$DOCMENTATION_DIR/util.md" |
Tom Hiller | 785dee0 | 2018-07-26 21:33:35 -0400 | [diff] [blame] | 19 | echo "$SUMMARY" >> "$DOCMENTATION_DIR/util.md" |
Tom Hiller | ed6d1e6 | 2018-07-21 00:23:17 -0400 | [diff] [blame] | 20 | |
| 21 | for DESC_FILE in $DESCRIPTION_FILES; do |
| 22 | UTIL_NAME=$(echo "$DESC_FILE" | rev | cut -d '/' -f2 | rev) |
| 23 | DESC=$(cat "$DESC_FILE") |
| 24 | |
| 25 | if [[ $DESC == "__"${UTIL_NAME}* || $DESC == "__["${UTIL_NAME}* ]]; then |
| 26 | DESC="* $DESC" |
| 27 | else |
| 28 | DESC="* __${UTIL_NAME}__ - $DESC" |
| 29 | fi |
| 30 | |
| 31 | # format description to under 72 characters per line and only |
| 32 | # breaking on whitespace |
| 33 | DESC=$(echo "$DESC" \ |
| 34 | | tr '\r\n' ' ' \ |
| 35 | | sed 's/ [*]\+/\n\t\*/g' \ |
| 36 | | sed 's/ \+/ /g' \ |
| 37 | | fold -s -w72 \ |
| 38 | | sed 's/\s*$//') |
| 39 | |
| 40 | echo "$DESC" >> "$UTIL_DIR/README.md" |
| 41 | echo "$DESC" >> "$DOCMENTATION_DIR/util.md" |
| 42 | done |