From 2aa088e0e6fffe2a8322dd4b8178b4e8f54b857e Mon Sep 17 00:00:00 2001 From: araspitzu Date: Wed, 3 Apr 2019 19:19:56 +0200 Subject: [PATCH] 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] --- eclair-core/eclair-cli | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/eclair-core/eclair-cli b/eclair-core/eclair-cli index f002c9531..31d60109f 100755 --- a/eclair-core/eclair-cli +++ b/eclair-core/eclair-cli @@ -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 API's password -a
Override the API URL with
- -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: " 1>&2; +Full documentation here: " 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"