summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-05-27 12:45:40 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-05-27 12:45:40 -0400
commitd13ea2efafcaea45961b43a736261fe35bf2a6e7 (patch)
tree3edf06b28ee04924ad57cd08af615fd8f8e1a55e
parent2f9a68282883a508861dcf48c15790af953286f6 (diff)
libreblacklist: learn `-h`
-rwxr-xr-xsrc/lib/libreblacklist46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist
index 293f3ac..6876a2b 100755
--- a/src/lib/libreblacklist
+++ b/src/lib/libreblacklist
@@ -19,7 +19,7 @@
. $(librelib conf.sh)
# Usage: blacklist-normalize <$file
-# Normalizes the syntax of the blacklist on stdin.
+# Normalizes the syntax of the blacklist on stdin
blacklist-normalize() {
sed -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/'
}
@@ -77,25 +77,61 @@ blacklist-lookup() {
}
# Usage: blacklist-cat | blacklist-get-pkg
-# Outputs only the package name field of the blacklist line(s) on stdin.
+# Prints only the package name field of the blacklist line(s) on stdin.
blacklist-get-pkg() {
blacklist-normalize | cut -d: -f1
}
# Usage: blacklist-cat | blacklist-get-rep
-# Outputs only the replacement package field of the blacklist line(s) on stdin.
+# Prints only the replacement package field of the blacklist line(s) on stdin.
blacklist-get-rep() {
blacklist-normalize | cut -d: -f2
}
# Usage: blacklist-cat | blacklist-get-reason
-# Outputs only the reason field of the blacklist line(s) on stdin.
+# Prints only the reason field of the blacklist line(s) on stdin.
blacklist-get-reason() {
blacklist-normalize | cut -d: -f3-
}
if [[ "${0##*/}" == libreblacklist ]]; then
+ usage-outside() {
+ sed -n '/^# Usage:/,/()/p' $0 |
+ tr '\n' '\r' | sed 's/\s*()\s*[{(]/\n/g'
+ }
+ usage-inside() {
+ sed 's/\r/\n/g'<<<"$1"|sed '/^$/d'
+ }
+ usage() {
+ if [[ $# == 0 ]]; then
+ printf "Usage: %s [-h] COMMAND [ARGUMENTS]\n" "${0##*/}"
+ echo "Tool for working with the nonfree software blacklist"
+ echo
+ echo "Commands:"
+ usage-outside | while read -r sec; do sec="$(usage-inside "$sec")"
+ <<<"$sec" sed -n \
+ -e 's/blacklist-//g' \
+ -e 's/^# //' \
+ -e '2p;$p' |
+ tac|tr '\n' '\t'
+ echo
+ done|column -t -s"$(printf '\t')"|sed 's/^/ /'
+ else
+ usage-outside | while read -r sec; do sec="$(usage-inside "$sec")"
+ cmd=$(<<<"$sec" sed -n 's/.*blacklist[ -]//;$p')
+ if [[ "$cmd" == "$1" ]]; then
+ <<<"$sec" sed -n \
+ -e "s/blacklist-/${0##*/} /g" \
+ -e 's/^# //p'
+ fi
+ done
+ fi
+ }
_blacklist_cmd=$1
shift
- "blacklist-$_blacklist_cmd" "$@"
+ if [[ $_blacklist_cmd == -h ]]; then
+ usage "$@"
+ else
+ "blacklist-$_blacklist_cmd" "$@"
+ fi
fi