added getopt like error for missing option parameters

This commit is contained in:
BVK Chaitanya 2010-04-12 21:33:03 +05:30
parent 8f33d5549f
commit b02c7c8fb5
8 changed files with 120 additions and 30 deletions

View file

@ -105,6 +105,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -120,37 +131,37 @@ do
exit 0 ;;
--modules)
modules=$1; shift;;
modules=`argument $option "$@"`; shift;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--font)
font=$1; shift;;
font=`argument $option "$@"`; shift;;
--font=*)
font=`echo "$option" | sed 's/--font=//'` ;;
--root-directory)
rootdir=$1; shift;;
rootdir=`argument $option "$@"`; shift;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-setup)
grub_setup=$1; shift;;
grub_setup=`argument $option "$@"`; shift;;
--grub-setup=*)
grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;;
--grub-mkimage)
grub_mkimage=$1; shift;;
grub_mkimage=`argument $option "$@"`; shift;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=$1; shift;;
grub_mkdevicemap=`argument $option "$@"`; shift;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-probe)
grub_probe=$1; shift;;
grub_probe=`argument $option "$@"`; shift;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;
@ -161,7 +172,7 @@ do
--disk-module)
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
disk_module=$1; shift;
disk_module=`argument $option "$@"`; shift;
fi ;;
--disk-module=*)
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then

View file

@ -49,6 +49,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -63,9 +74,7 @@ do
echo "$0 (GNU GRUB ${package_version})"
exit 0 ;;
-o | --output)
grub_cfg=$1
shift
;;
grub_cfg=`argument $option "$@"`; shift;;
--output=*)
grub_cfg=`echo "$option" | sed 's/--output=//'`
;;
@ -74,6 +83,10 @@ do
usage
exit 1
;;
*)
echo "Invalid parameter, $option" 1>&2
exit 1
;;
esac
done

View file

@ -51,6 +51,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -66,18 +77,18 @@ do
exit 0 ;;
--modules)
modules=$1; shift ;;
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
-o | --output)
output_image=$1; shift ;;
output_image=`argument $option "$@"`; shift ;;
--output=*)
output_image=`echo "$option" | sed 's/--output=//'` ;;
# Intentionally undocumented
--override-directory)
override_dir=$1
override_dir=`argument $option "$@"`
shift
PATH=${override_dir}:$PATH
export PATH
@ -93,7 +104,7 @@ do
exit 1
;;
*)
source="${source} ${option}" ;;
source="${source} ${option} $@"; break ;;
esac
done

View file

@ -44,6 +44,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -59,7 +70,7 @@ do
exit 0 ;;
--root-directory)
rootdir=$1; shift ;;
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;

View file

@ -44,6 +44,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -59,7 +70,7 @@ do
exit 0 ;;
--root-directory)
rootdir=$1; shift ;;
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;

View file

@ -71,6 +71,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -86,27 +97,27 @@ do
exit 0 ;;
--modules)
modules=$1; shift ;;
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory)
rootdir=$1; shift ;;
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-mkimage)
grub_mkimage=$1; shift ;;
grub_mkimage=`argument $option "$@"`; shift ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=$1; shift ;;
grub_mkdevicemap=`argument $option "$@"`; shift ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-probe)
grub_probe=$1; shift ;;
grub_probe=`argument $option "$@"`; shift ;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;

View file

@ -74,6 +74,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
@ -89,27 +100,27 @@ do
exit 0 ;;
--modules)
modules=$1; shift ;;
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--root-directory)
rootdir=$1; shift ;;
rootdir=`argument $option "$@"`; shift ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
--grub-mkdevicemap)
grub_mkdevicemap=$1; shift ;;
grub_mkdevicemap=`argument $option "$@"`; shift ;;
--grub-mkdevicemap=*)
grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;;
--grub-mkimage)
grub_mkimage=$1; shift ;;
grub_mkimage=`argument $option "$@"`; shift ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;
--grub-probe)
grub_probe=$1; shift ;;
grub_probe=`argument $option "$@"`; shift ;;
--grub-probe=*)
grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;;

View file

@ -52,6 +52,17 @@ Report bugs to <bug-grub@gnu.org>.
EOF
}
argument () {
opt=$1
shift
if test $# -eq 0; then
echo "$0: option requires an argument -- '$opt'" 1>&2
exit 1
fi
echo $1
}
input_dir=${pkglibdir}
# Check the arguments.
@ -69,17 +80,17 @@ do
exit 0 ;;
--modules)
modules=$1; shift ;;
modules=`argument $option "$@"`; shift ;;
--modules=*)
modules=`echo "$option" | sed 's/--modules=//'` ;;
--pkglibdir)
input_dir=$1; shift ;;
input_dir=`argument $option "$@"`; shift ;;
--pkglibdir=*)
input_dir=`echo "$option" | sed 's/--pkglibdir=//'` ;;
--grub-mkimage)
grub_mkimage=$1; shift ;;
grub_mkimage=`argument $option "$@"`; shift ;;
--grub-mkimage=*)
grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;