Fix issue #46: Deprecate getopt

This commit is contained in:
Filippo Squillace 2015-01-08 02:04:04 +01:00
parent ebc9dcbd38
commit 7610e75260
3 changed files with 23 additions and 21 deletions

View file

@ -88,7 +88,6 @@ of GNU/Linux distributions. The needed executables in the host OS are:
- bash
- wget or curl
- tar
- getopt
- id
- mkdir

View file

@ -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

View file

@ -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)