From 86dc2a6d71b9330991ab48b9ba00936cd8370182 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 17 Apr 2012 19:39:45 -0400 Subject: lsinitcpio: adopt parseopts for option parsing Signed-off-by: Dave Reisner --- lsinitcpio | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'lsinitcpio') diff --git a/lsinitcpio b/lsinitcpio index 02a87ca..aa97df7 100755 --- a/lsinitcpio +++ b/lsinitcpio @@ -13,15 +13,15 @@ declare FUNCTIONS=functions usage() { cat< 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 -- cgit v1.2.3-24-g4f1b