Commit 54b8db6b by Kaarle Ritvanen Committed by Stéphane Graber

lxc-alpine: use getopt to parse options

parent 8bdc1262
...@@ -278,12 +278,6 @@ usage_err() { ...@@ -278,12 +278,6 @@ usage_err() {
exit 1 exit 1
} }
optarg_check() {
if [ -z "$2" ]; then
usage_err "option '$1' requires an argument"
fi
}
default_path=@LXCPATH@ default_path=@LXCPATH@
release= release=
arch=$(uname -m) arch=$(uname -m)
...@@ -294,58 +288,39 @@ if [ $(id -u) -ne 0 ]; then ...@@ -294,58 +288,39 @@ if [ $(id -u) -ne 0 ]; then
exit 1 exit 1
fi fi
options=$(getopt -o hn:p:r:R:a: -l help,name:,rootfs:,path:,repository:,release:,arch: -- "$@")
[ $? -eq 0 ] || usage_err
eval set -- "$options"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
opt="$1" case "$1" in
shift
case "$opt" in
-h|--help) -h|--help)
usage usage
exit 0 exit 0
;; ;;
-n|--name) -n|--name)
optarg_check $opt "$1" name=$2
name=$1
shift
;; ;;
--rootfs) --rootfs)
optarg_check $opt "$1" rootfs=$2
rootfs=$1
shift
;; ;;
-p|--path) -p|--path)
optarg_check $opt "$1" path=$2
path=$1
shift
;; ;;
-r|--repository) -r|--repository)
optarg_check $opt "$1" repository=$2
repository=$1
shift
;; ;;
-R|--release) -R|--release)
optarg_check $opt "$1" release=$2
release=$1
shift
;; ;;
-a|--arch) -a|--arch)
optarg_check $opt "$1" arch=$2
arch=$1
shift
;; ;;
--) --)
shift
break;; break;;
--*=*)
# split --myopt=foo=bar into --myopt foo=bar
set -- ${opt%=*} ${opt#*=} "$@"
;;
-?)
usage_err "unknown option '$opt'"
;;
-*)
# split opts -abc into -a -b -c
set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
;;
esac esac
shift 2
done done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment