summaryrefslogtreecommitdiff
path: root/util/util_readme
diff options
context:
space:
mode:
authorTom Hiller <thrilleratplay@gmail.com>2018-07-21 00:23:17 -0400
committerPatrick Rudolph <siro@das-labor.org>2018-07-26 13:26:29 +0000
commited6d1e6dcca71715edb8f284958fc2fddecfeb8c (patch)
tree0bd8aca90d8363532400b468e12ae76a89a4ca7a /util/util_readme
parentde690a30a4c5c9f22dec0c606a82cf10216ecaf7 (diff)
downloadcoreboot-ed6d1e6dcca71715edb8f284958fc2fddecfeb8c.tar.xz
util: Add util_readme script
Bash script to concatenate description.md files into ./util/README.md and Documention/Util.md Change-Id: I015ae6816ea74cacb7f0332fda2c3ebef205c1e2 Signed-off-by: Tom Hiller <thrilleratplay@gmail.com> Reviewed-on: https://review.coreboot.org/27564 Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/util_readme')
-rw-r--r--util/util_readme/description.md1
-rwxr-xr-xutil/util_readme/util_readme.sh40
2 files changed, 41 insertions, 0 deletions
diff --git a/util/util_readme/description.md b/util/util_readme/description.md
new file mode 100644
index 0000000000..4b8f596064
--- /dev/null
+++ b/util/util_readme/description.md
@@ -0,0 +1 @@
+Creates README.md of description files in `./util` subdirectories `Bash`
diff --git a/util/util_readme/util_readme.sh b/util/util_readme/util_readme.sh
new file mode 100755
index 0000000000..251661442c
--- /dev/null
+++ b/util/util_readme/util_readme.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+# Creates `./util/README.md` and `./Documentation/Util.md` of description files
+# in `./util` subdirectories
+#
+# Execute from root of project. Example:
+# `sh util/util_readme/util_readme.sh`
+
+UTIL_README_DIR="$(cd "$(dirname "$0")" || exit; pwd -P)"
+UTIL_DIR=$(dirname "$UTIL_README_DIR")
+COREBOOT_ROOT_DIR=$(dirname "$UTIL_DIR")
+DOCMENTATION_DIR="$COREBOOT_ROOT_DIR/Documentation"
+
+DESCRIPTION_FILES=$(find "$UTIL_DIR" -name "description.md" | sort)
+
+echo -n "" > "$UTIL_DIR/README.md"
+echo "# Utilities" > "$DOCMENTATION_DIR/util.md"
+
+for DESC_FILE in $DESCRIPTION_FILES; do
+ UTIL_NAME=$(echo "$DESC_FILE" | rev | cut -d '/' -f2 | rev)
+ DESC=$(cat "$DESC_FILE")
+
+ if [[ $DESC == "__"${UTIL_NAME}* || $DESC == "__["${UTIL_NAME}* ]]; then
+ DESC="* $DESC"
+ else
+ DESC="* __${UTIL_NAME}__ - $DESC"
+ fi
+
+ # format description to under 72 characters per line and only
+ # breaking on whitespace
+ DESC=$(echo "$DESC" \
+ | tr '\r\n' ' ' \
+ | sed 's/ [*]\+/\n\t\*/g' \
+ | sed 's/ \+/ /g' \
+ | fold -s -w72 \
+ | sed 's/\s*$//')
+
+ echo "$DESC" >> "$UTIL_DIR/README.md"
+ echo "$DESC" >> "$DOCMENTATION_DIR/util.md"
+done