diff --git a/ada/ada b/ada/ada index fd4997b..06e6a7d 100755 --- a/ada/ada +++ b/ada/ada @@ -183,7 +183,7 @@ usage() { --unstage --from-file Release files in the list. - --stat-request + --stat-request Show status of bulk request for given request-id --events [--resume] [--force] [--recursive] [--timeout s] @@ -301,7 +301,7 @@ set_defaults() { # The ADA_VERSION value will be automatically updated by Github action Update-ada-version.yml # For a release, it will contain the version number (like v3.1). # For a branch, it will contain the branch name. - ADA_VERSION="master" + ADA_VERSION="125-args-error-message" args= api= debug=false @@ -407,6 +407,7 @@ get_args() { exit 1 ;; --tokenfile ) + check_arg "tokenfile" $2 auth_method=tokenfile tokenfile="$2" #Check if authentication file is passed as argument @@ -449,6 +450,7 @@ get_args() { shift ;; --api ) + check_arg "api" $2 api="$2" shift ; shift ;; @@ -462,55 +464,68 @@ get_args() { ;; --list ) command='list' + check_arg $command $2 path="$2" shift ; shift ;; --longlist ) command='longlist' if [ "$2" = "--from-file" ] ; then + check_arg "from-file" $3 $debug && echo "Reading list '$3'" pathlist=$(<"$3") shift ; shift ; shift else + check_arg "longlist" $2 pathlist="$2" shift ; shift fi ;; --stat ) + check_arg "stat" $2 command='stat' path="$2" shift ; shift ;; --mkdir ) command='mkdir' + check_arg $command $2 path="$2" shift ; shift ;; --mv ) command='mv' + check_arg $command $2 + check_arg $command $3 path="$2" destination="$3" shift ; shift ; shift ;; --delete ) command='delete' + check_arg $command $2 path="$2" shift ; shift ;; --setlabel ) command='setlabel' + check_arg $command $2 + check_arg $command $3 path="$2" label="$3" shift ; shift ; shift ;; --rmlabel ) command='rmlabel' + check_arg $command $2 + check_arg $command $3 path="$2" label="$3" shift ; shift ; shift ;; --lslabel ) command='lslabel' + check_arg $command $2 path="$2" shift ; shift # Optinal argument: a label the user wants to see. @@ -527,15 +542,18 @@ get_args() { ;; --findlabel ) command='findlabel' + check_arg $command $2 + check_arg $command $3 path=$(echo "$2" | sed 's:/*$::') regex="$3" shift ; shift ; shift ;; --setxattr ) command='setxattr' + check_arg $command $2 path="$2" shift ; shift - # Optinal argument: filename containing the attributes (or - for stdin) + # Optional argument: filename containing the attributes (or - for stdin) case $1 in --* | '' ) # Next argument is another option or absent; not a file name. @@ -562,6 +580,7 @@ get_args() { ;; --lsxattr ) command='lsxattr' + check_arg $command $2 path="$2" shift ; shift # Optinal argument: name of an attribute @@ -578,6 +597,9 @@ get_args() { ;; --findxattr ) command='findxattr' + check_arg $command $2 + check_arg $command $3 + check_arg $command $4 # Strip trailing slashes path=$(echo "$2" | sed 's:/*$::') attribute_name="$3" @@ -586,6 +608,10 @@ get_args() { ;; --rmxattr ) command='rmxattr' + check_arg $command $2 + if [[ $3 != '--all' ]] ; then + check_arg $command $3 + fi path="$2" attribute_name="$3" shift ; shift ; shift @@ -593,9 +619,11 @@ get_args() { --checksum ) command='checksum' if [ "$2" = "--from-file" ] ; then + check_arg "from-file" $3 pathlist=$(<"$3") shift ; shift ; shift else + check_arg "checksum" $2 pathlist="$2" shift ; shift fi @@ -603,10 +631,12 @@ get_args() { --stage ) command='stage' if [[ $2 =~ ^--from-?file ]] ; then + check_arg "from-file" $3 from_file=true pathlist=$(<"$3") shift ; shift ; shift else + check_arg "stage" $2 from_file=false pathlist="$2" shift ; shift @@ -615,32 +645,40 @@ get_args() { --unstage ) command='unstage' if [[ $2 =~ ^--from-?file ]] ; then + check_arg "from-file" $3 from_file=true pathlist=$(<"$3") shift ; shift ; shift else + check_arg "unstage" $2 from_file=false pathlist="$2" shift ; shift fi ;; --request-id ) + check_arg "request_id" $2 request_id="$2" shift ; shift ;; --stat-request ) command='stat-request' + check_arg $command $2 request_id="$2" shift ; shift ;; --events ) command='events' + check_arg $command $2 + check_arg $command $3 channel_name="$2" path="$3" shift ; shift ; shift ;; --report-staged ) command='report-staged' + check_arg $command $2 + check_arg $command $3 channel_name="$2" path="$3" shift ; shift ; shift @@ -658,12 +696,14 @@ get_args() { shift ;; --lifetime ) + check_arg "lifetime" $2 arg="$2" lifetime=${arg::${#arg} -1} lifetime_unit=${arg: ${#arg}-1} shift ; shift ;; --timeout ) + check_arg "timeout" $2 channel_timeout="$2" shift ; shift ;; @@ -675,6 +715,7 @@ get_args() { ;; * ) # This must be a channel name + check_arg $command $2 channel_name="$2" shift ;; @@ -682,7 +723,8 @@ get_args() { shift ;; --delete-channel ) - command='delete-channel' + command='delete-channel' + check_arg $command $2 channel_name="$2" shift ; shift ;; @@ -694,6 +736,7 @@ get_args() { ;; * ) # This must be a poolgroup + check_arg $command $2 poolgroup="$2" shift ;; @@ -741,6 +784,15 @@ get_args() { # Define internal functions ada needs # +check_arg() { + option=$1 + arg=$2 + if [[ $arg == --* || $arg == '' ]]; then + echo 1>&2 "ERROR: option --$option requires next argument" + exit 1 + fi +} + view_token() { local token="$1" @@ -783,7 +835,6 @@ view_token() { } - validate_expiration_timestamp () { local exp_unix="$1" # Expiration timestamp (unix format) local token_debug_info="$2" # Additional info for error message