Mail archive
alpine-devel

Re: [alpine-devel] [PATCH 3/4] update-conf: accept long options

From: Natanael Copa <ncopa_at_alpinelinux.org>
Date: Wed, 3 Jul 2013 15:30:33 +0200

On Mon, 1 Jul 2013 17:14:16 -0400
Dubiousjim <dubiousjim_at_gmail.com> wrote:

> ---
> update-conf.in | 40 +++++++++++++++++++++++++---------------
> 1 file changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/update-conf.in b/update-conf.in
> index 6a8ab16..da4208c 100644
> --- a/update-conf.in
> +++ b/update-conf.in
> _at_@ -10,14 +10,16 @@ init_tmpdir TMPD
> LBUCACHE="$TMPD/lbucache"
>
> usage() {
> - echo "$PROGRAM $VERSION
> -Usage: $PROGAM [-aihl]
> + cat >&2 << __EOF__
> +$PROGRAM $VERSION - TODO what is it?
> +Usage: $PROGRAM [-a|--all] [-i|--initd] [-l|--list] [-h|--help]
> +Options:
> + -a, --all Select all updated files
> + -i, --initd Use all new init.d scripts
> + -l, --list List updated files
> + -h, --help Show this help
>
> - -a Select all updated files.
> - -h Show this help.
> - -i Use all new init.d scripts.
> - -l List updated files.
> -"
> +__EOF__
> }
>
>
> _at_@ -31,15 +33,23 @@ is_initd() {
> echo "$1" | grep etc/init.d/ > /dev/null
> }
>
> -while getopts "alih" opt ; do
> - case "$opt" in
> - a) aflag="-a" ;;
> - i) iflag="-i" ;;
> - l) lflag="-l" ;;
> - h|*) usage;;
> - esac
> +args=`getopt -o ailh --long all,initd,list,help -n "$PROGRAM" -- "$_at_"`

I don't think this is posix shell compatible.

We already use various extensions like 'local' and shell replace
expansion ${var/search/replace} so we already depend on an extended shell.

I think this is ok for now, but we should be aware of that this is
moving away from posix shell compat.

Is long options worth it?

I also made a posix shell implementation for parsing options for lxc
templates which we could use instead.

-nc


> +if [ $? -ne 0 ]; then
> + usage
> + exit 2
> +fi
> +eval set -- "$args"
> +while true; do
> + case $1 in
> + -a|--all) aflag="-a";;
> + -i|--initd) iflag="-i";;
> + -l|--list) lflag="-l";;
> + -h|--help) usage; exit;;
> + --) shift; break;;
> + *) exit 1;; # getopt error
> + esac
> + shift
> done
> -shift `expr $OPTIND - 1`
>
> for apknew in $(find "$ROOT/etc" -name '*.apk-new') ; do
> p="${apknew%.apk-new}"



---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Wed Jul 03 2013 - 15:30:33 UTC