From 7610e752600ea72f2145b9e91016eb2e3258b593 Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Thu, 8 Jan 2015 02:04:04 +0100 Subject: [PATCH] Fix issue #46: Deprecate getopt --- README.md | 1 - bin/juju | 9 ++++----- tests/test_juju.sh | 34 +++++++++++++++++++--------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1f71b8c..7bba017 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,6 @@ of GNU/Linux distributions. The needed executables in the host OS are: - bash - wget or curl - tar -- getopt - id - mkdir diff --git a/bin/juju b/bin/juju index 80ea83c..065fd04 100755 --- a/bin/juju +++ b/bin/juju @@ -112,9 +112,6 @@ check_cli(){ function parse_arguments(){ - TEMP=$(getopt -o drp:fbi:hv --long delete,root,proot-args:,fakeroot,build-image,setup-from-file:,help,version -n "$CMD" -- "$@") - eval set -- "$TEMP" - OPT_SETUP_FROM_FILE=false IMAGE_FILE="" OPT_FAKEROOT=false @@ -125,7 +122,8 @@ function parse_arguments(){ OPT_DELETE=false OPT_HELP=false OPT_VERSION=false - while true ; do + for opt in $@ + do case "$1" in -i|--setup-from-file) OPT_SETUP_FROM_FILE=true ; shift ; IMAGE_FILE=$1 ; shift ;; -f|--fakeroot) OPT_FAKEROOT=true ; shift ;; @@ -136,7 +134,8 @@ function parse_arguments(){ -h|--help) OPT_HELP=true ; shift ;; -v|--version) OPT_VERSION=true ; shift ;; --) shift ; break ;; - *) die "Internal error!" ;; + -*) die "Invalid option $1" ;; + *) break ;; esac done diff --git a/tests/test_juju.sh b/tests/test_juju.sh index 58d641a..0c2e748 100755 --- a/tests/test_juju.sh +++ b/tests/test_juju.sh @@ -24,13 +24,17 @@ function setup_juju(){ echo "setup_juju" } function run_juju_as_fakeroot(){ - echo "run_juju_as_fakeroot $@" + local proot_args="$1" + shift + echo "run_juju_as_fakeroot($proot_args,$@)" } function run_juju_as_root(){ echo "run_juju_as_root $@" } function run_juju_as_user(){ - echo "run_juju_as_user $@" + local proot_args="$1" + shift + echo "run_juju_as_user($proot_args,$@)" } function wrap_juju(){ @@ -75,27 +79,27 @@ function test_delete_juju(){ } function test_run_juju_as_fakeroot(){ local output=$(wrap_juju -f) - is_equal $output "run_juju_as_fakeroot" || return 1 + is_equal $output "run_juju_as_fakeroot(,)" || return 1 local output=$(wrap_juju --fakeroot) - is_equal $output "run_juju_as_fakeroot" || return 1 + is_equal $output "run_juju_as_fakeroot(,)" || return 1 local output=$(wrap_juju -f -p "-b arg") - is_equal "${output[@]}" "run_juju_as_fakeroot -b arg" || return 1 - local output=$(wrap_juju -f -p "-b arg" -- command) - is_equal "${output[@]}" "run_juju_as_fakeroot -b arg command" || return 1 - local output=$(wrap_juju -f command) - is_equal "${output[@]}" "run_juju_as_fakeroot command" || return 1 + is_equal "${output[@]}" "run_juju_as_fakeroot(-b arg,)" || return 1 + local output=$(wrap_juju -f -p "-b arg" -- command -kv) + is_equal "${output[@]}" "run_juju_as_fakeroot(-b arg,command -kv)" || return 1 + local output=$(wrap_juju -f command --as) + is_equal "${output[@]}" "run_juju_as_fakeroot(,command --as)" || return 1 } function test_run_juju_as_user(){ local output=$(wrap_juju) - is_equal $output "run_juju_as_user" || return 1 + is_equal $output "run_juju_as_user(,)" || return 1 local output=$(wrap_juju -p "-b arg") - is_equal "${output[@]}" "run_juju_as_user -b arg" || return 1 - local output=$(wrap_juju -p "-b arg" -- command) - is_equal "${output[@]}" "run_juju_as_user -b arg command" || return 1 - local output=$(wrap_juju command) - is_equal "${output[@]}" "run_juju_as_user command" || return 1 + is_equal "${output[@]}" "run_juju_as_user(-b arg,)" || return 1 + local output=$(wrap_juju -p "-b arg" -- command -ll) + is_equal "${output[@]}" "run_juju_as_user(-b arg,command -ll)" || return 1 + local output=$(wrap_juju command -ls) + is_equal "${output[@]}" "run_juju_as_user(,command -ls)" || return 1 } function test_run_juju_as_root(){ local output=$(wrap_juju -r)