2018-07-23 15:06:04 -07:00
|
|
|
#!/usr/bin/env bash
|
2018-05-17 14:16:22 +09:30
|
|
|
# Needs bash for process substitition, ie <(
|
|
|
|
|
|
|
|
if [ $# != 2 ]; then
|
2019-08-10 12:50:31 +02:00
|
|
|
echo "Usage $0 <command> <markdown.md>" >&2
|
2018-05-17 14:16:22 +09:30
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
get_cmd_opts()
|
|
|
|
{
|
2023-08-18 16:19:14 +09:30
|
|
|
# Trim out -- after first one: ensure width sufficient to give desc
|
|
|
|
# on same line, and ignore single-letter prefix e.g. -X|--ex
|
|
|
|
COLUMNS=1000 $1 --help | sed -n 's/^\(-.|\)\?\(--[^ ]*\)\( \| \).*/\2/p' | while IFS=$'\n' read -r opt; do
|
2018-05-17 14:16:22 +09:30
|
|
|
case "$opt" in
|
|
|
|
# We don't document dev options.
|
|
|
|
--dev*)
|
|
|
|
;;
|
|
|
|
--*=*|--*' <arg>'*)
|
|
|
|
echo "${opt%%[ =]*}=" | cut -c3-
|
|
|
|
;;
|
|
|
|
--*)
|
|
|
|
echo "${opt%%[ |]*}" | cut -c3-
|
|
|
|
;;
|
|
|
|
-*\|--*)
|
|
|
|
opt=${opt##*|}
|
|
|
|
echo "${opt%%[ |]*}" | cut -c3-
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-08-18 16:19:14 +09:30
|
|
|
# If we don't get any, we failed!
|
2018-05-17 14:16:22 +09:30
|
|
|
CMD_OPTNAMES=$(get_cmd_opts "$1" | sort)
|
2023-08-18 16:19:14 +09:30
|
|
|
if [ -z "$CMD_OPTNAMES" ]; then
|
|
|
|
echo "Failed to get options from $0!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-05-17 14:16:22 +09:30
|
|
|
|
|
|
|
# Now, gather (long) opt names from man page, make sure they match.
|
2023-08-18 16:19:14 +09:30
|
|
|
MAN_OPTNAMES=$(sed -E -n 's,^\* \*\*(--)?([^*/]*)\*\*(/\*\*-.\*\*)?(=?).*,\2\4,p' < "$2" | sort)
|
2018-05-17 14:16:22 +09:30
|
|
|
|
2021-11-04 15:13:43 +01:00
|
|
|
# Remove undocumented proprieties, usually these proprieties are
|
|
|
|
# under experimental phases.
|
|
|
|
for flag in $(jq '.flags[]' <doc/undoc-flags.json) ; do
|
|
|
|
# Remove the quotes from the string, so the code will remove
|
|
|
|
# the first and last char in the string.
|
|
|
|
FLAG=$(sed 's/.//;s/.$//' <(echo "$flag"))
|
|
|
|
CMD_OPTNAMES=$(sed "/$FLAG=/d" <(echo "$CMD_OPTNAMES"))
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2018-05-17 14:16:22 +09:30
|
|
|
if [ "$CMD_OPTNAMES" != "$MAN_OPTNAMES" ]; then
|
|
|
|
echo "diff of command names vs manpage names":
|
2023-08-18 16:19:14 +09:30
|
|
|
diff -u --label="$1" <(echo "$CMD_OPTNAMES") --label="$2" <(echo "$MAN_OPTNAMES")
|
2018-05-17 14:16:22 +09:30
|
|
|
exit 2
|
|
|
|
fi
|