`gcloud` list of results into result list
Occasionally, I want to be able to take multiline results from a gcloud command and map these onto something else. Most recently, I wanted to turn the results into a repeated list of flags.
E.g.:
From a list of Project IDs
gcloud projects list --format='value(projectId)'
Into --project=${A},--project=${B},...--project=${Z}
For posterity, one way to do this is to combine gcloud’s value (which is csv[no-headings]), replacing the default newline (\n) terminator with e.g. ,, and using gcloud’s format projection which works like (its underlying) Python format command:
gcloud projects list \
--format='value[terminator=","](format("--project={0}",projectId))'