Improve readmes

This commit is contained in:
Jeremy Soller
2019-03-18 12:26:17 -06:00
parent d5ab76f9db
commit 1b1c3b87f2
12 changed files with 49 additions and 54 deletions

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
set -e
cargo build --manifest-path "scripts/modeltool/Cargo.toml" --release
MODELTOOL="$(realpath "scripts/modeltool/target/release/modeltool")"
for dir in models/*/
do
pushd "$dir" > /dev/null
model="$(basename "$dir")"
echo -e "\x1B[1m$model\x1B[0m"
cp README.md.in README.md
echo "## Firmware Versions" >> README.md
"$MODELTOOL" . | tee -a README.md
popd > /dev/null
done

View File

@@ -22,6 +22,7 @@ function readme_model {
echo >> README.md
echo "## Contents" >> README.md
echo >> README.md
"$MODELTOOL" . >> README.md
popd > /dev/null
}
@@ -34,24 +35,25 @@ done
function readme_line {
echo -e " \x1B[1m$1\x1B[0m" >&2
if [ -f "$1/README.md" ]
name="$(basename "$1")"
description=""
readme="$(find "$1" -maxdepth 1 -iname README.md)"
if [ -n "$readme" ]
then
# Get first line, removing the trailing pounds and spaces
description="$(head -n 1 "$1/README.md" | sed -e 's/^[#[:space:]]*//')"
else
# Use the directory name as the description
description="$(basename "$1")"
description=" - $(head -n 1 "$readme" | sed -e 's/^[#[:space:]]*//')"
fi
submodule="$(git submodule status "$1" 2> /dev/null | cut -d ' ' -f 3 || true)"
if [ "$submodule" == "$dir" ]
if [ "$submodule" == "$1" ]
then
# Link to submodule URL
origin="$(git -C "$dir" remote get-url origin)"
echo "- [$description]($origin)"
origin="$(git -C "$1" remote get-url origin)"
echo "- [$name]($origin)$description"
else
# Link to directory
echo "- [$description](./$dir)"
echo "- [$name](./$1)$description"
fi
}
@@ -63,6 +65,7 @@ function readme_dir {
echo >> README.md
echo "## Contents" >> README.md
echo >> README.md
for dir in */
do
readme_line "${dir%/}" >> README.md