Add --debug option & don't display request by default

This commit is contained in:
Samantaz Fox 2022-02-14 17:11:53 +01:00
parent 3244003608
commit d24f7a9c59

View file

@ -17,6 +17,8 @@ print_help()
echo " -i,--interactive Run in interactive mode" echo " -i,--interactive Run in interactive mode"
echo " -o,--output Print output to file instead of stdout" echo " -o,--output Print output to file instead of stdout"
echo "" echo ""
echo " --debug Show what is sent to the API"
echo ""
} }
print_clients() print_clients()
@ -47,7 +49,7 @@ query_with_default()
prompt="$1" prompt="$1"
default="$2" default="$2"
printf "\n%s [%s]: " "$prompt" "$default" >&2 printf "%s [%s]: " "$prompt" "$default" >&2
read -r data read -r data
if [ -z "$data" ]; then if [ -z "$data" ]; then
@ -62,7 +64,7 @@ query_with_error()
prompt="$1" prompt="$1"
error_message="$2" error_message="$2"
printf "\n%s []: " "$prompt" >&2 printf "%s []: " "$prompt" >&2
read -r data read -r data
if [ -z "$data" ]; then if [ -z "$data" ]; then
@ -83,6 +85,7 @@ is_arg()
-h|--help) true;; -h|--help) true;;
-i|--interactive) true;; -i|--interactive) true;;
-o|--output) true;; -o|--output) true;;
--debug) true;;
*) false;; *) false;;
esac esac
} }
@ -93,6 +96,7 @@ is_arg()
# #
interactive=false interactive=false
debug=false
client_option="" client_option=""
endpoint_option="" endpoint_option=""
@ -162,6 +166,10 @@ while :; do
output="$1" output="$1"
;; ;;
--debug)
debug=true
;;
*) *)
echo "Error: unknown argument '$1'" echo "Error: unknown argument '$1'"
exit 2 exit 2
@ -392,8 +400,12 @@ if [ $interactive = true ]; then
data="{\"context\":{\"client\":{$client}},$partial_data}" data="{\"context\":{\"client\":{$client}},$partial_data}"
# Basic debug # Basic debug
if [ $debug = true ]; then
echo
echo "sending:" echo "sending:"
echo "$data" | sed 's/{/{\n/g; s/}/\n}/g; s/,/,\n/g' echo "$data" | sed 's/{/{\n/g; s/}/\n}/g; s/,/,\n/g'
echo
fi
fi fi