Re: [PATCH 2/4] easy-build.sh: use getopts instead of rolling our own option parsing.
On Fri, 2009-08-07 at 14:05 +0200, Frans Pop wrote:
> On Friday 07 August 2009, Ian Campbell wrote:
> > +while getopts d:h OPT ; do
>
> Is getopts also supported in dash?
I believe so.
I just tried it and it looks like the script is already not dash-ready:
$ dash -x ./easy-build.sh -h
+ set -e
+ export CF=CONF.sh
+ . CONF.sh
.: 1: CONF.sh: not found
(Just to show dash knows about getops since the above didn't get that
far:
$ dash -c 'getopts'
getopts: 1: Usage: getopts optstring var [arg]
)
> > + case $OPT in
> > + d)
> > + case $OPTARG in
> > + # Note: "gnome" is the special gnome task, not the generic task
> > + gnome|kde|lxde|xfce|light|all)
> > + desktop=$2
> > + ;;
> > + *)
> > + show_usage
> > + exit 1
> > + ;;
> > + esac ;;
> > + h) show_usage; exit 1;;
>
> Please put the commands for the "h" option on separate lines (as is done
> for the others).
Done.
> AFAIK a plain 'show_usage', if not displayed as the result of an error,
> should have an 'exit 0'.
Done.
> The -h option should be listed in the usage output.
Done.
> Maybe it would be good to also support --help if -h is added.
Since getopts doesn't support long options I agree with Max that it
isn't worth the complexity.
Updated patch below.
Ian.
easy-build.sh: use getopts instead of rolling our own option parsing.
---
easy-build.sh | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/easy-build.sh b/easy-build.sh
index c586c1e..5e7a31a 100755
--- a/easy-build.sh
+++ b/easy-build.sh
@@ -6,7 +6,7 @@ set -e
## See also CONF.sh for the meaning of variables used here.
show_usage() {
- echo "Usage: $(basename $0) [-d gnome|kde|lxde|xfce|light|all] BC|NETINST|CD|DVD [<ARCH> ...]"
+ echo "Usage: $(basename $0) [-h] [-d gnome|kde|lxde|xfce|light|all] BC|NETINST|CD|DVD [<ARCH> ...]"
}
@@ -25,19 +25,26 @@ if [ $# -eq 0 ]; then
fi
desktop=
-if [ "$1" = "-d" ]; then
- case $2 in
- # Note: "gnome" is the special gnome task, not the generic task
- gnome|kde|lxde|xfce|light|all)
- desktop=$2
- shift 2
- ;;
- *)
+while getopts d:h OPT ; do
+ case $OPT in
+ d)
+ case $OPTARG in
+ # Note: "gnome" is the special gnome task, not the generic task
+ gnome|kde|lxde|xfce|light|all)
+ desktop=$2
+ ;;
+ *)
+ show_usage
+ exit 1
+ ;;
+ esac ;;
+ h)
show_usage
- exit 1
+ exit 0
;;
esac
-fi
+done
+shift $(expr $OPTIND - 1)
export DISKTYPE="$1"
shift
--
1.6.3.3
--
Ian Campbell
Current Noise: Witchcraft - It's So Easy
Logic is the chastity belt of the mind!
Reply to: