diff options
author | Senthil Kumaran S <senthil.kumaran@linaro.org> | 2018-02-02 22:29:35 +0530 |
---|---|---|
committer | Senthil Kumaran S <senthil.kumaran@linaro.org> | 2018-02-05 11:47:48 +0530 |
commit | bd76eabc224b3d00971bd5bf2e0affb899ce1c7f (patch) | |
tree | 894e71c8b480b6973d8c5fed9e81e2166272b2da | |
parent | 13951ca6403c4b7484bfeab5398812d7293c9f5d (diff) |
Use getopts to parse arguments.
Change-Id: Iec634dcca16156aa004de2c83e3d2e323fef67ea
-rwxr-xr-x | lxc-attach | 24 | ||||
-rwxr-xr-x | lxc-create | 24 | ||||
-rwxr-xr-x | lxc-destroy | 24 | ||||
-rwxr-xr-x | lxc-info | 34 |
4 files changed, 38 insertions, 68 deletions
@@ -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 @@ -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 @@ -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 |