From: Andre Noll Date: Sun, 5 Mar 2017 21:36:25 +0000 (+0100) Subject: subcommand: Move gsu_check_arg_count(). X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d4dd63ffba45377ae7ff9fb341e1dce31382ef4f;p=gsu.git subcommand: Move gsu_check_arg_count(). It is called from gsu_getopts() which is defined further up in the file. This does not really matter in bash, but it is still confusing, so let's move gsu_check_arg_count() up. Pure code movement, no changes. --- diff --git a/subcommand b/subcommand index 343f248..b12783b 100644 --- a/subcommand +++ b/subcommand @@ -50,6 +50,35 @@ _gsu_available_commands() } | sort | tr '\n' ' ')" } +# Check number of arguments. +# +# Usage: gsu_check_arg_count [] +# +# Check that is between and inclusively. +# If only ist given, num2 is assumed to be infinity. +# +# Examples: +# 0 0 no argument allowed +# 1 1 exactly one argument required +# 0 2 at most two arguments admissible +# 2 at least two arguments required +gsu_check_arg_count() +{ + ret=-$E_GSU_BAD_ARG_COUNT + if (($# == 2)); then # only num1 is given + result="at least $2 args required, $1 given" + (($1 < $2)) && return + ret=$GSU_SUCCESS + return + fi + # num1 and num2 given + result="need at least $2 args, $1 given" + (($1 < $2)) && return + result="need at most $3 args, $1 given" + (($1 > $3)) && return + ret=$GSU_SUCCESS +} + _gsu_print_available_commands() { local cmd cmds @@ -556,32 +585,3 @@ gsu() _gsu_print_available_commands exit 1 } - -# Check number of arguments. -# -# Usage: gsu_check_arg_count [] -# -# Check that is between and inclusively. -# If only ist given, num2 is assumed to be infinity. -# -# Examples: -# 0 0 no argument allowed -# 1 1 exactly one argument required -# 0 2 at most two arguments admissible -# 2 at least two arguments required -gsu_check_arg_count() -{ - ret=-$E_GSU_BAD_ARG_COUNT - if (($# == 2)); then # only num1 is given - result="at least $2 args required, $1 given" - (($1 < $2)) && return - ret=$GSU_SUCCESS - return - fi - # num1 and num2 given - result="need at least $2 args, $1 given" - (($1 < $2)) && return - result="need at most $3 args, $1 given" - (($1 > $3)) && return - ret=$GSU_SUCCESS -}