summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSenthil Kumaran S <senthil.kumaran@linaro.org>2018-02-02 22:29:35 +0530
committerSenthil Kumaran S <senthil.kumaran@linaro.org>2018-02-05 11:47:48 +0530
commitbd76eabc224b3d00971bd5bf2e0affb899ce1c7f (patch)
tree894e71c8b480b6973d8c5fed9e81e2166272b2da
parent13951ca6403c4b7484bfeab5398812d7293c9f5d (diff)
Use getopts to parse arguments.
Change-Id: Iec634dcca16156aa004de2c83e3d2e323fef67ea
-rwxr-xr-xlxc-attach24
-rwxr-xr-xlxc-create24
-rwxr-xr-xlxc-destroy24
-rwxr-xr-xlxc-info34
4 files changed, 38 insertions, 68 deletions
diff --git a/lxc-attach b/lxc-attach
index 43fa80e..f563456 100755
--- a/lxc-attach
+++ b/lxc-attach
@@ -13,22 +13,14 @@
CMD=$(awk -F'-- ' '{print $2}' <<< "$@")
-POSITIONAL=()
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
- -n)
- LXC_NAME="$2"
- shift
- shift
- ;;
- *)
- POSITIONAL+=("$1")
- shift
- ;;
-esac
+while getopts "n:" opt; do
+ case $opt in
+ n)
+ LXC_NAME="$OPTARG"
+ ;;
+ *)
+ ;;
+ esac
done
if [ "$CMD" ]; then
diff --git a/lxc-create b/lxc-create
index c5a76d8..95b53be 100755
--- a/lxc-create
+++ b/lxc-create
@@ -14,22 +14,14 @@
# Get the list of requested packages.
PACKAGES=$(sed 's/,/ /g' <<< $(cut -d' ' -f1 <<< $(awk -F'--packages ' '{print $2}' <<< "$@")))
-POSITIONAL=()
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
- -n)
- LXC_NAME="$2"
- shift
- shift
- ;;
- *)
- POSITIONAL+=("$1")
- shift
- ;;
-esac
+while getopts "qt:n:" opt; do
+ case $opt in
+ n)
+ LXC_NAME="$OPTARG"
+ ;;
+ *)
+ ;;
+ esac
done
if [ "$PACKAGES" ]; then
diff --git a/lxc-destroy b/lxc-destroy
index bc020c1..92aac7e 100755
--- a/lxc-destroy
+++ b/lxc-destroy
@@ -11,22 +11,14 @@
#
# Mocks lxc-destroy command which is used by LAVA.
-POSITIONAL=()
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
- -n)
- LXC_NAME="$2"
- shift
- shift
- ;;
- *)
- POSITIONAL+=("$1")
- shift
- ;;
-esac
+while getopts "fn:" opt; do
+ case $opt in
+ n)
+ LXC_NAME="$OPTARG"
+ ;;
+ *)
+ ;;
+ esac
done
if [ "$LXC_NAME" ]; then
diff --git a/lxc-info b/lxc-info
index 608aaab..c71b425 100755
--- a/lxc-info
+++ b/lxc-info
@@ -11,26 +11,20 @@
#
# Mocks lxc-info command which is used by LAVA.
-while [[ $# -gt 0 ]]
-do
-key="$1"
-
-case $key in
- -sH)
- STATUS=1
- shift
- ;;
- -iH)
- IP=1
- shift
- ;;
- -n)
- LXC_NAME="$2"
- shift
- shift
- ;;
- *)
-esac
+while getopts "s:i:n:" opt; do
+ case $opt in
+ n)
+ LXC_NAME="$OPTARG"
+ ;;
+ s)
+ STATUS=1
+ ;;
+ i)
+ IP=1
+ ;;
+ *)
+ ;;
+ esac
done
if [ "$STATUS" ]; then