1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/bin/bash
helpfile=$1
name=$2
name2desc=$3
th=$(echo ${name} | tr '[a-z]' '[A-Z]')
ver=${4}
apidate=${5}
cr="
"
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@" ; exit 1; }
Usage() {
cat <<EOF
Usage: ${0##*/} helpfile name name2desc-file version apidate
helpfile: file with output from --help of command
name: the name of this command
name2desc-file: file that contains tab delimited name:description pairs
EOF
}
[ $# -eq 4 ] || { Usage 1>&2; exit 1; }
[ -z "${ver}" ] && ver=$( head -n4 RELEASENOTES.TXT | tail -n1 | \
sed -n 's,.* \([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\).*,\1,p')
OIFS=${IFS}
TEMP_D=""
cleanup() {
[ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
}
TEMP_D=$(mktemp -d ${TMPDIR:-/tmp}/${0##*/}.XXXXXX)
trap cleanup EXIT
helpout="${TEMP_D}/helpout"
sed 's,^[ ][ ],,' "${helpfile}" > "${helpout}"
IFS=${cr}
sections=( $(egrep "^[A-Z][A-Z ]*$" "${helpout}" ) )
IFS=${OIFS}
getsection() {
local sec=$1 file=$2
local sa # sed args
local ee="--expression="
sa=( -e "/^${sec}$/,/^[A-Z][A-Z ]*/!d" )
sa[${#sa[@]}]="-e"
sa[${#sa[@]}]="s/^${sec}$/.SH ${sec}\n.PP/"
sa[${#sa[@]}]=$ee's/--\([a-zA-Z-]*\)/\\fB--\1\\fR/g'
sa[${#sa[@]}]=$ee's/^\([[:space:]]*\)-\([a-zA-Z?]\)/\1\\fB-\2\\fR/'
sa[${#sa[@]}]=$ee's/-/\\-/g'
sed "${sa[@]}" "$file" | sed -e 's,^ , ,' -e '$d'
}
desc=$(awk '-F\t' '$1 == name { print $2 }' "name=${name}" "${name2desc}")
[ -n "$desc" ] ||
fail "No description found for $name in $name2desc"
printf '.TH %s "%s" "%s" "%s" "%s"\n' "${th}" 1 "${ver} api=${apidate}" \
"Auto Scaling command line tools" "User Commands"
cat <<EOF
.SH NAME
${name} \- ${desc}
EOF
for x in "${sections[@]}"; do
getsection "${x}" "${helpout}"
done
verurl="http://docs.amazonwebservices.com/AutoScaling/${apidate}/DeveloperGuide/"
latesturl="http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/"
cat <<EOF
.SH SEE ALSO
${verurl}
${latesturl}
EOF
exit 0
|