[lxc-devel] [PATCH] lxc-alpine: use getopt to parse options
Stéphane Graber
stgraber at ubuntu.com
Mon Sep 28 19:50:23 UTC 2015
On Mon, Sep 28, 2015 at 02:51:21PM +0300, Kaarle Ritvanen wrote:
> Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen at datakunkku.fi>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> templates/lxc-alpine.in | 51 +++++++++++++------------------------------------
> 1 file changed, 13 insertions(+), 38 deletions(-)
>
> diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
> index d62f891..29c7b7c 100644
> --- a/templates/lxc-alpine.in
> +++ b/templates/lxc-alpine.in
> @@ -277,12 +277,6 @@ usage_err() {
> exit 1
> }
>
> -optarg_check() {
> - if [ -z "$2" ]; then
> - usage_err "option '$1' requires an argument"
> - fi
> -}
> -
> default_path=@LXCPATH@
> release=
> arch=$(uname -m)
> @@ -293,58 +287,39 @@ if [ $(id -u) -ne 0 ]; then
> exit 1
> 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
> - opt="$1"
> - shift
> - case "$opt" in
> + case "$1" in
> -h|--help)
> usage
> exit 0
> ;;
> -n|--name)
> - optarg_check $opt "$1"
> - name=$1
> - shift
> + name=$2
> ;;
> --rootfs)
> - optarg_check $opt "$1"
> - rootfs=$1
> - shift
> + rootfs=$2
> ;;
> -p|--path)
> - optarg_check $opt "$1"
> - path=$1
> - shift
> + path=$2
> ;;
> -r|--repository)
> - optarg_check $opt "$1"
> - repository=$1
> - shift
> + repository=$2
> ;;
> -R|--release)
> - optarg_check $opt "$1"
> - release=$1
> - shift
> + release=$2
> ;;
> -a|--arch)
> - optarg_check $opt "$1"
> - arch=$1
> - shift
> + arch=$2
> ;;
> --)
> + shift
> 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
> + shift 2
> done
>
>
> --
> 2.1.0
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150928/9c9689d3/attachment.sig>
More information about the lxc-devel
mailing list