From 2ef93a247c1e233f94a132d48ff32f3707b39df1 Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Thu, 16 Oct 2025 15:57:54 +0200 Subject: [PATCH 1/3] Check commandline arguments --- ada/ada | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/ada/ada b/ada/ada index 4b7c13a..1946475 100755 --- a/ada/ada +++ b/ada/ada @@ -405,6 +405,7 @@ get_args() { exit 1 ;; --tokenfile ) + check_arg "tokenfile" $2 auth_method=tokenfile tokenfile="$2" #Check if authentication file is passed as argument @@ -447,6 +448,7 @@ get_args() { shift ;; --api ) + check_arg "api" $2 api="$2" shift ; shift ;; @@ -460,55 +462,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. @@ -525,15 +540,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. @@ -560,6 +578,7 @@ get_args() { ;; --lsxattr ) command='lsxattr' + check_arg $command $2 path="$2" shift ; shift # Optinal argument: name of an attribute @@ -576,6 +595,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" @@ -584,6 +606,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 @@ -591,9 +617,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 @@ -601,10 +629,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 @@ -613,32 +643,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 @@ -656,12 +694,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 ;; @@ -673,6 +713,7 @@ get_args() { ;; * ) # This must be a channel name + check_arg $command $2 channel_name="$2" shift ;; @@ -680,7 +721,8 @@ get_args() { shift ;; --delete-channel ) - command='delete-channel' + command='delete-channel' + check_arg $command $2 channel_name="$2" shift ; shift ;; @@ -692,6 +734,7 @@ get_args() { ;; * ) # This must be a poolgroup + check_arg $command $2 poolgroup="$2" shift ;; @@ -739,6 +782,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" @@ -781,7 +833,6 @@ view_token() { } - validate_expiration_timestamp () { local exp_unix="$1" # Expiration timestamp (unix format) local token_debug_info="$2" # Additional info for error message From 8bff3d4be060dfdbb666bc8925ac7b1ac604bb67 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 22 Oct 2025 13:37:31 +0000 Subject: [PATCH 2/3] Set version to 125-args-error-message --- ada/ada | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ada/ada b/ada/ada index 59cdc09..770f7af 100755 --- a/ada/ada +++ b/ada/ada @@ -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 From e21f2f5edbcc42c60f1f0623f8660875cc990849 Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Wed, 22 Oct 2025 15:39:55 +0200 Subject: [PATCH 3/3] Fix indent --- ada/ada | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ada/ada b/ada/ada index 59cdc09..bae555b 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]