1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flohmarkt_ynh.git synced 2024-09-03 18:36:30 +02:00

new argument --seperator

to allow choosing how provided data will be concatenated
This commit is contained in:
Chris Vogel 2024-05-30 12:58:37 +02:00
parent e1ec0e97e1
commit b87ce1299e

View file

@ -12,6 +12,8 @@ ynh_local_curl() {
# | arg: -m --method: request method to use: POST (default), PUT, GET, DELETE
# | arg: -H --header: add a header to the request (can be used multiple times)
# | arg: -d --data: data to be PUT or POSTed. Can be used multiple times.
# | arg: -s --seperator: seperator used to concatenate POST/PUT --date or key=value ('none'=no seperator)
# | arg: (default for POST: '&', default for PUT: ' ')
# | arg: -u --user: login username (requires --password)
# | arg: -p --password: login password
# | arg: -n --no_sleep: don't sleep 2 seconds (background: https://github.com/YunoHost/yunohost/pull/547)
@ -47,7 +49,7 @@ ynh_local_curl() {
# Declare an array to define the options of this helper.a
local -A supported_methods=( [PUT]=1 [POST]=1 [GET]=1 [DELETE]=1 )
local legacy_args=Ld
local -A args_array=( [l]=line_match= [m]=method= [H]=header= [n]=no_sleep [L]=location= [d]=data= [u]=user= [p]=password= )
local -A args_array=( [l]=line_match= [m]=method= [H]=header= [n]=no_sleep [L]=location= [d]=data= [u]=user= [p]=password= [s]=seperator= )
local line_match
local method
local -a header
@ -55,6 +57,7 @@ ynh_local_curl() {
local location
local user
local password
local seperator
local -a data
local -a curl_opt_args # optional arguments to `curl`
# Manage arguments with getopts
@ -85,9 +88,13 @@ ynh_local_curl() {
# PUT: all elements of $data concatenated in one string
# GET: no data
# DELETE: no data
local seperator='&'
if [[ "$method" == 'PUT' ]]; then
# if not defined by --seperator set default
if [[ -v seperator ]] && [[ "$seperator" == 'none' ]]; then
seperator=''
elif ! [[ -v seperator ]] && [[ "$method" == 'PUT' ]]; then
seperator=''
elif ! [[ -v seperator ]]; then
seperator='&'
fi
join_by() { local IFS="$1"; shift; echo "$*"; }
local P_DATA=$( join_by "$seperator" ${data[@]} )