+if [ "$method" = list ]; then
+ if [ $# -eq 0 -o "$1" = '-o' ]; then
+ if [ "$1" = '-o' -a $# -gt 1 ]; then
+ echo "$method with -o switch does not accept arguments" >&2
+ usage
+ exit 1
+ fi
+ # ignore getopt's --, we don't care if an arg begins with - anyway
+ [ "$1" = '--' ] && switch >/dev/null
+
+ # OPTIMIZE: getting deps of virtual packages is slow, it would be
+ # great to use apk info -R from show_reqs in orphan loop
+ all=$(apk info)
+ # show packages if no args
+ if [ $# -eq 0 ]; then
+ for x in $(echo "$all" | grep '^\.'); do
+ show_reqs "$(prepend_dot "$x")"
+ done
+ fi
+ # set all child packages of virtual packages as owned
+ for v in $(echo "$all" | grep '^\.'); do
+ for c in $(apk info -R $v | tail +2 | grep -v '^\.'); do
+ # NOTE: use tr because shell may not have ksh-derived ${c//}
+ # XXX: package name may have illegal chars for variable name
+ # past those already replaced, and replacing chars may
+ # result in variable collision—but official apk repos do
+ # not have any packages that would cause issues
+ eval "__$(echo $c | tr -s '.:-' _)=1"
+ done
+ done
+ # check world against owned packages
+ # TODO: notify user if package is in world and also a virtual package
+ orphans=$(
+ for x in $(cat /etc/apk/world | grep -v '^\.'); do
+ eval "[ \${__$(
+ echo $x | tr -s '.:-' _ | tr -s '<>=' "\n" | head -1
+ )-0} -eq 0 ]" && echo $x
+ done
+ )
+ if [ -z "$orphans" ]; then
+ echo "No orphan packages found."
+ else
+ show_reqs orphans $orphans
+ fi
+ else
+ for x in $*; do
+ show_reqs "$(prepend_dot "$x")"
+ done
+ fi
+ exit
+fi
+