From d4dd63ffba45377ae7ff9fb341e1dce31382ef4f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 5 Mar 2017 22:36:25 +0100 Subject: [PATCH] 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. --- subcommand | 58 +++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) 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 -} -- 2.39.2