0

I get a http response of the Hetzner API which provides information about all volumes. I want to build a menu with dialog, where you can choose out of all existing volumes. This way I get the API's answer:

ALL_VOLUMES_HTTP=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -H "Authorization: Bearer $1" https://api.hetzner.cloud/v1/volumes)

which is filtered by jq in this way

ALL_VOLUME_NAMES=$(jq '.volumes[].name' <<< "$ALL_VOLUMES_HTTP")

the output of ALL_VOLUME_NAMES is formatted like this

"volumeName1"
"volumeName2"

but in the menu dialog it is displayed like in this image

I already tried to put brackets about the jq (jq '[.volumes[].name') but it is displayed completely wrong too like in this example

For generating the interface I am using the following code:

SELECTED_VOLUME=$(dialog --title "Volume mount" --menu "Select:" 0 0 0 $ALL_VOLUME_NAMES 3>&1 1>&2 2>&3)

So how can I generate a correct menu interface in dialog with the given data?

L. Feger
  • 1
  • 3
  • Possible duplicate of [Concat numbers from JSON without doublequotes using jq](https://stackoverflow.com/questions/33947584/concat-numbers-from-json-without-doublequotes-using-jq) – Benjamin W. Oct 21 '18 at 17:17
  • It's not clear how the GUI menu is generated from the jq output. Please clarify, otherwise your Q is in danger of being closed. Also the filter mentioned in the Q (`'[.volumes[].name'`) is syntactically invalid, so you must have mistyped it when writing the Q. – peak Oct 21 '18 at 18:20

1 Answers1

0

It is possible to concat the information to one string. This results in this code:

ALL_VOLUMES_HTTP=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -H "Authorization: Bearer $1" https://api.hetzner.cloud/v1/volumes)
ALL_VOLUME_NAMES=$(echo $ALL_VOLUMES_HTTP | jq -r '.volumes[].name')

VALUES=""
for i in $ALL_VOLUME_NAMES; do
        VALUES="$VALUES $(jq -r '.volumes[]|select(.name=="'$i'")|.id' <<< "$ALL_VOLUMES_HTTP") $i"
done

SELECTED_VOLUME=$(dialog --title "Volume mount" --menu "Select: " 0 0 0 $VALUES 3>&1 1>&2 2>&3)
L. Feger
  • 1
  • 3