summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-18 01:39:45 +0200
committerDave Reisner <dreisner@archlinux.org>2012-04-22 05:43:52 +0200
commit86dc2a6d71b9330991ab48b9ba00936cd8370182 (patch)
tree18e9774eea22100a6e6d9942a47f6628c094a32b
parentfa5484c81c40e0a5a05194909600716f39ce0faf (diff)
downloadmkinitcpio-86dc2a6d71b9330991ab48b9ba00936cd8370182.tar.gz
mkinitcpio-86dc2a6d71b9330991ab48b9ba00936cd8370182.tar.xz
lsinitcpio: adopt parseopts for option parsing
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r--bash-completion16
-rwxr-xr-xlsinitcpio46
2 files changed, 41 insertions, 21 deletions
diff --git a/bash-completion b/bash-completion
index f4c476b..b7ab5bc 100644
--- a/bash-completion
+++ b/bash-completion
@@ -2,18 +2,22 @@
# mkinitcpio bash completion by Seblu <seblu@seblu.net>
_lsinitcpio() {
- local action cur
- action="-a -h -n -v -x"
+ local cur opts
+ opts=(-a --analyze -h --help -n --nocolor -v --verbose -x --extract)
+
_get_comp_words_by_ref cur
- case "$cur" in
- -*) COMPREPLY=($(compgen -W "${action}" -- "$cur"));;
- *) _filedir;;
+
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur")) ;;
+ *)
+ _filedir ;;
esac
}
_find_kernel_versions() {
local -a matches
- local regex
+ local dir regex
# add completions from kernels in /boot
regex="Linux kernel.*version"
diff --git a/lsinitcpio b/lsinitcpio
index 02a87ca..aa97df7 100755
--- a/lsinitcpio
+++ b/lsinitcpio
@@ -13,15 +13,15 @@ declare FUNCTIONS=functions
usage() {
cat<<USAGE
-lsinitramfs %VERSION%
+lsinitcpio %VERSION%
usage: ${0##*/} [options] <initramfs>
Options:
- -a analyze contents
- -h display this help
- -n disable colorized output
- -v more verbose output
- -x extract image to disk
+ -a, --analyze analyze contents
+ -h, --help display this help
+ -n, --nocolor disable colorized output
+ -v, --verbose more verbose output
+ -x, --extract extract image to disk
USAGE
exit 1
@@ -39,17 +39,33 @@ die() {
exit 1
}
-while getopts ':ahnvx' flag; do
- case $flag in
- a) analyze=1 ;;
- h) usage ;;
- n) color=0 ;;
- v) verbose='--verbose' ;;
- x) unset list ;;
- \?) die "invalid option -- '$OPTARG'" ;;
+OPT_SHORT='ahnvx'
+OPT_LONG=('analyze' 'help' 'nocolor' 'verbose' 'extract')
+
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
+ exit 1
+fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
+ case $1 in
+ -a|--analyze)
+ analyze=1 ;;
+ -h|--help)
+ usage ;;
+ -n|--nocolor)
+ color=0 ;;
+ -v|--verbose)
+ verbose='--verbose' ;;
+ -x|--extract)
+ unset list ;;
+ --)
+ shift
+ break 2 ;;
esac
+ shift
done
-shift $(( OPTIND - 1 ))
declare image=$1