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.
|
2023-09-21 15:06:26 +09:30
|
|
|
--dev-*)
|
2018-05-17 14:16:22 +09:30
|
|
|
;;
|
|
|
|
--*=*|--*' <arg>'*)
|
|
|
|
echo "${opt%%[ =]*}=" | cut -c3-
|
|
|
|
;;
|
|
|
|
--*)
|
|
|
|
echo "${opt%%[ |]*}" | cut -c3-
|
|
|
|
;;
|
|
|
|
-*\|--*)
|
|
|
|
opt=${opt##*|}
|
|
|
|
echo "${opt%%[ |]*}" | cut -c3-
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-08-18 16:19:16 +09:30
|
|
|
# Remove undocumented proprieties, usually these proprieties are
|
|
|
|
# under experimental phases.
|
|
|
|
remove_undoc()
|
|
|
|
{
|
|
|
|
# shellcheck disable=SC2162
|
|
|
|
while read OPT; do
|
|
|
|
grep -q "^$OPT$" < doc/undoc-flags.list || echo "$OPT"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-08-18 16:19:14 +09:30
|
|
|
# If we don't get any, we failed!
|
2023-08-18 16:19:16 +09:30
|
|
|
CMD_OPTNAMES=$(get_cmd_opts "$1" | sort | remove_undoc)
|
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:16 +09:30
|
|
|
MAN_OPTNAMES=$(grep -vi 'deprecated in' "$2" | sed -E -n 's,^\* \*\*(--)?([^*/]*)\*\*(/\*\*-.\*\*)?(=?).*,\2\4,p'| sort)
|
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
|