mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-15 13:55:09 -05:00
paccache: adopt parseopts for options parsing
Add longopts and update usage. This removes the TODO item and incorporates --help/--version into the standard option set. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
This commit is contained in:
parent
ea4aa6f184
commit
6d10de881e
@ -88,7 +88,7 @@ uninstall-local:
|
|||||||
|
|
||||||
bacman: $(srcdir)/bacman.sh.in
|
bacman: $(srcdir)/bacman.sh.in
|
||||||
bash_completion: $(srcdir)/bash_completion.in
|
bash_completion: $(srcdir)/bash_completion.in
|
||||||
paccache: $(srcdir)/paccache.sh.in
|
paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/scripts/library/parseopts.sh
|
||||||
pacdiff: $(srcdir)/pacdiff.sh.in
|
pacdiff: $(srcdir)/pacdiff.sh.in
|
||||||
paclist: $(srcdir)/paclist.sh.in
|
paclist: $(srcdir)/paclist.sh.in
|
||||||
paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in
|
paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in
|
||||||
|
@ -42,6 +42,8 @@ die() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m4_include(../scripts/library/parseopts.sh)
|
||||||
|
|
||||||
# reads a list of files on stdin and prints out deletion candidates
|
# reads a list of files on stdin and prints out deletion candidates
|
||||||
pkgfilter() {
|
pkgfilter() {
|
||||||
# there's whitelist and blacklist parameters passed to this
|
# there's whitelist and blacklist parameters passed to this
|
||||||
@ -184,21 +186,21 @@ options to help control how much, and what, is deleted from any directory
|
|||||||
containing pacman package tarballs.
|
containing pacman package tarballs.
|
||||||
|
|
||||||
Operations:
|
Operations:
|
||||||
-d perform a dry run, only finding candidate packages.
|
-d, --dryrun perform a dry run, only finding candidate packages.
|
||||||
-m <movedir> move candidate packages to 'movedir'.
|
-m, --move <dir> move candidate packages to 'movedir'.
|
||||||
-r remove candidate packages.
|
-r, --remove remove candidate packages.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-a <arch> scan for 'arch' (default: all architectures).
|
-a, --arch <arch> scan for 'arch' (default: all architectures).
|
||||||
-c <cachedir> scan 'cachedir' for packages (default: @localstatedir@/cache/pacman/pkg).
|
-c, --cachedir <dir> scan 'cachedir' for packages (default: @localstatedir@/cache/pacman/pkg).
|
||||||
-f apply force to mv(1) and rm(1) operations.
|
-f, --force apply force to mv(1) and rm(1) operations.
|
||||||
-h display this help message.
|
-h, --help display this help message and exit.
|
||||||
-i <pkgs> ignore 'pkgs', which is a comma separated. Alternatively,
|
-i, --ignore <pkgs> ignore 'pkgs', comma separated. Alternatively, specify '-' to
|
||||||
specify '-' to read package names from stdin, newline delimited.
|
read package names from stdin, newline delimited.
|
||||||
-k <num> keep 'num' of each package in 'cachedir' (default: 3).
|
-k, --keep <num> keep 'num' of each package in 'cachedir' (default: 3).
|
||||||
-u target uninstalled packages.
|
-u, --uninstalled target uninstalled packages.
|
||||||
-v increase verbosity. specify up to 3 times.
|
-v, --verbose increase verbosity. specify up to 3 times.
|
||||||
-z use null delimiters for candidate names (only with -v and -vv)
|
-z, --null use null delimiters for candidate names (only with -v and -vv)
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -213,47 +215,70 @@ if (( ! UID )); then
|
|||||||
exit 42
|
exit 42
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO: remove this workaround and use a sane command line parser (like the
|
OPT_SHORT=':a:c:dfhi:k:m:rsuVvz'
|
||||||
# parse_options library from scripts/) here
|
OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move'
|
||||||
if [[ $1 = -@(h|-help) ]]; then
|
'remove' 'uninstalled' 'version' 'verbose' 'null')
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
elif [[ $1 = -@(V|-version) ]]; then
|
|
||||||
version
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
while getopts ':a:c:dfi:k:m:rsuvz' opt; do
|
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
|
||||||
case $opt in
|
exit 1
|
||||||
a) scanarch=$OPTARG ;;
|
fi
|
||||||
c) cachedir=$OPTARG ;;
|
set -- "${OPTRET[@]}"
|
||||||
d) dryrun=1 ;;
|
unset OPT_SHORT OPT_LONG OPTRET
|
||||||
f) cmdopts=(-f) ;;
|
|
||||||
i) if [[ $OPTARG = '-' ]]; then
|
while :; do
|
||||||
|
case $1 in
|
||||||
|
-a|--arch)
|
||||||
|
scanarch=$2
|
||||||
|
shift ;;
|
||||||
|
-c|--cachedir)
|
||||||
|
cachedir=$2
|
||||||
|
shift ;;
|
||||||
|
-d|--dryrun)
|
||||||
|
dryrun=1 ;;
|
||||||
|
-f|--force)
|
||||||
|
cmdopts=(-f) ;;
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0 ;;
|
||||||
|
-i|--ignore)
|
||||||
|
if [[ $2 = '-' ]]; then
|
||||||
[[ ! -t 0 ]] && IFS=$'\n' read -r -d '' -a ign
|
[[ ! -t 0 ]] && IFS=$'\n' read -r -d '' -a ign
|
||||||
else
|
else
|
||||||
IFS=',' read -r -a ign <<< "$OPTARG"
|
IFS=',' read -r -a ign <<< "$2"
|
||||||
fi
|
fi
|
||||||
blacklist+=("${ign[@]}")
|
blacklist+=("${ign[@]}")
|
||||||
unset i ign ;;
|
unset i ign
|
||||||
k) keep=$OPTARG
|
shift ;;
|
||||||
|
-k|--keep)
|
||||||
|
keep=$2
|
||||||
if [[ -z $keep || -n ${keep//[0-9]/} ]]; then
|
if [[ -z $keep || -n ${keep//[0-9]/} ]]; then
|
||||||
die 'argument to option -k must be a non-negative integer'
|
die 'argument to option -k must be a non-negative integer'
|
||||||
else
|
else
|
||||||
keep=$(( 10#$keep ))
|
keep=$(( 10#$keep ))
|
||||||
fi ;;
|
fi
|
||||||
m) move=1 movedir=$OPTARG ;;
|
shift ;;
|
||||||
r) delete=1 ;;
|
-m|--move)
|
||||||
u) IFS=$'\n' read -r -d '' -a ign < <(pacman -Qq)
|
move=1 movedir=$2
|
||||||
|
shift ;;
|
||||||
|
-r|--remove)
|
||||||
|
delete=1 ;;
|
||||||
|
-u|--uninstalled)
|
||||||
|
IFS=$'\n' read -r -d '' -a ign < <(pacman -Qq)
|
||||||
blacklist+=("${ign[@]}")
|
blacklist+=("${ign[@]}")
|
||||||
unset ign ;;
|
unset ign ;;
|
||||||
v) (( ++verbose )) ;;
|
-V|--version)
|
||||||
z) delim='\0' ;;
|
version
|
||||||
:) die "option '--%s' requires an argument" "$OPTARG" ;;
|
exit 0 ;;
|
||||||
?) die "invalid option -- '%s'" "$OPTARG" ;;
|
-v|--verbose)
|
||||||
|
(( ++verbose )) ;;
|
||||||
|
-z|--null)
|
||||||
|
delim='\0' ;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break 2 ;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
shift $(( OPTIND - 1 ))
|
|
||||||
|
|
||||||
# remaining args are a whitelist
|
# remaining args are a whitelist
|
||||||
whitelist=("$@")
|
whitelist=("$@")
|
||||||
|
Loading…
Reference in New Issue
Block a user