1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-22 22:25:26 +01:00

Fix eclair-cli to work with equal sign in arguments (#926)

* Fix eclair cli argument passing

* Modify eclair-cli to work with equals in arguments

* Eclair-cli: show usage when wrong params are received

* Remove deprecated call from eclair-cli help message [ci skip]
This commit is contained in:
araspitzu 2019-04-03 19:19:56 +02:00 committed by Pierre-Marie Padiou
parent 3a56ad9133
commit 2aa088e0e6

View file

@ -18,12 +18,13 @@ on <$api_url>.
Usage
-----
\e[93meclair-cli\e[39m [\e[93mOPTIONS\e[39m]... [\e[93mCOMMAND\e[39m] [--command-param command-value]...
\e[93meclair-cli\e[39m [\e[93mOPTIONS\e[39m]... <\e[93mCOMMAND\e[39m> [--command-param=command-value]...
where OPTIONS can be:
-p <password> API's password
-a <address> Override the API URL with <address>
-h Show available commands
-h Show this help
-s Some commands can print a trimmed JSON
and COMMAND is one of:
getinfo, connect, open, close, forceclose, updaterelayfee,
@ -34,12 +35,11 @@ and COMMAND is one of:
Examples
--------
eclair-cli help display available commands
eclair-cli -a localhost:1234 peers list the peers of a node hosted on localhost:1234
eclair-cli close --channelId 006fb... closes the channel with id 006fb...
eclair-cli close --channelId=006fb... closes the channel with id 006fb...
Full documentation here: <https://acinq.github.io/apidoc>" 1>&2;
Full documentation here: <https://acinq.github.io/eclair>" 1>&2;
exit 1;
}
@ -72,25 +72,15 @@ if [ -z $api_endpoint ] || [ "$api_endpoint" == "help" ]; then
usage;
fi
# transform long options into a HTTP encoded url body.
# long options are expected to be of format: --param=param_value
api_payload=""
index=1
for arg in "${@}"; do
transformed_arg="";
case ${arg} in
"--"*) # if arg begins with two dashes, it is the name of a parameter. Dashes must be removed, and arg must be followed by an equal sign
# also, it must be prefixed by an '&' sign, if it is not the first argument
if [ $index -eq 1 ]; then
transformed_arg="$transformed_arg${arg:2}=";
else
transformed_arg="&$transformed_arg${arg:2}=";
fi
"--"*) api_payload="$api_payload --data-urlencode \"${arg:2}\"";
;;
*) transformed_arg=$arg
*) echo "incorrect argument, please use --arg=value"; usage;
;;
esac
api_payload="$api_payload$transformed_arg";
let "index++"
done;
# jq filter parses response body for error message
@ -116,4 +106,4 @@ else
fi
# we're now ready to execute the API call
eval curl "--user $auth --silent --show-error -X POST -H \"Content-Type: application/x-www-form-urlencoded\" -d '$api_payload' $api_url/$api_endpoint" | jq -r "$jq_filter"
eval curl "--user $auth --silent --show-error -X POST -H \"Content-Type: application/x-www-form-urlencoded\" $api_payload $api_url/$api_endpoint" | jq -r "$jq_filter"