cli icon indicating copy to clipboard operation
cli copied to clipboard

[enhancement - cli output] Add json output in addition to the existing text format

Open rjain-pivotal opened this issue 6 years ago • 19 comments

Reference : https://github.com/cloudfoundry/cli/issues/604

As a Cloud Foundry user who uses the CF CLI in scripts, I would like to get the cli output in a json format to easily parse the result of the executed commands.

Not sure why the previous issue #604 was closed without any resolution.

rjain-pivotal avatar Jul 05 '18 16:07 rjain-pivotal

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/158844125

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Jul 05 '18 16:07 cf-gitbot

+1

gklp avatar Jul 23 '18 07:07 gklp

+1

simonjohansson avatar Oct 15 '18 13:10 simonjohansson

+1

dawu415 avatar Oct 16 '18 23:10 dawu415

+1 - I used this feature repeatedly in the ActiveState Stackato CLI and can attest to its usability

ericpromislow avatar Oct 17 '18 07:10 ericpromislow

It also simplifies dealing with mapping GUIDS to human readable names since CF CLI has already done that for us. In the meantime, here is a bash snippet that handles pagination using JQ and CURL. It combines the resources array of objects. The results-per-page argument was for testing purposes to show that it works. You can decide if you want to process each dataset or the combined one.

next_url="/v2/apps?results-per-page=4"
((i=0))
mkdir -p /tmp/apps.$$
dataset="/tmp/apps.$$/dataset.${i}"
while [[ "${next_url}" != "null" ]]; do
    cf curl "${next_url}" > "${dataset}"
    datasets[i]="${dataset}"
    next_url=$(jq -r -c ".next_url" "${dataset}")
    ((i += 1))
    dataset="/tmp/apps.$$/dataset.${i}"
done

jq -s 'map(.resources[])' "${datasets[@]}"
rm -rf /tmp/apps.$$

norman-abramovitz avatar Nov 11 '18 14:11 norman-abramovitz

Hi @rjain-pivotal and everyone who has commented on this. This has been a popular Community feature, apologies we've not prioritised it thus far.

The CLI team is currently working on CLI v7 which is primarily focused on adopting CC API V3. At the moment, we are working on a small subset of features for CLI v6 and will be moving efforts for major development including features and enhancements of the CLI to v7 and other future major versions of the CLI.

The effort for CLI v7, as mentioned, is to accelerate the adoption of the CC API V3, which is a current high priority. We hope this effort will pay future dividends as development of both the CC API and the CLI will be easier, allowing for more features and enhancements which are/were not currently possible on CC API V2 (and CLI v6). We appreciate your patience during this transition period.

We hope to add a scripting solution to a major version of the CLI, and appreciate this feedback. Although we might not be able to prioritise this feature in the short term, we will be picking this back up in the near future. Please also do not hesitate to reach out if you have any questions about any of the above. Happy to go into more details.

abbyachau avatar Nov 27 '18 22:11 abbyachau

You can always use the cf curl command to get JSON output. Depending on what you are looking for, it is just as easy to process that output. Using just BASH and JQ you can accomplish a great deal. One of the nice features CF API returns to you is most of the URLs you will need with the GUIDs filled in for next level of details you might be looking for.

On Tue, Nov 27, 2018 at 2:03 PM Abby Chau [email protected] wrote:

Hi @rjain-pivotal https://github.com/rjain-pivotal and everyone who has commented on this. This has been a popular Community feature, apologies we've not prioritised it thus far.

The CLI team is currently working on CLI v7 which is primarily focused on adopting CC API V3. At the moment, we are working on a small subset of features for CLI v6 and will be moving efforts for major development including features and enhancements of the CLI to v7 and other future major versions of the CLI.

The effort for CLI v7, as mentioned, is to accelerate the adoption of the CC API V3, which is a current high priority. We hope this effort will pay future dividends as development of both the CC API and the CLI will be easier, allowing for more features and enhancements which are/were not currently possible on CC API V2 (and CLI v6). We appreciate your patience during this transition period.

We hope to add a scripting solution to a major version of the CLI, and appreciate this feedback. Although we might not be able to prioritise this feature in the short term, we will be picking this back up in the near future. Please also do not hesitate to reach out if you have any questions about any of the above. Happy to go into more details.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cloudfoundry/cli/issues/1415#issuecomment-442234423, or mute the thread https://github.com/notifications/unsubscribe-auth/ANHhKJQ3V_7mjCQaF_LUcAyJv0qDNud8ks5uzbaVgaJpZM4VEJ-3 .

-- Norman Abramovitz Technical Director Stark & Wayne, LLC

norman-abramovitz avatar Nov 28 '18 14:11 norman-abramovitz

@abbyachau where can we go to see progress on v7 on this feature (and others)?

jchesterpivotal avatar Jan 30 '19 16:01 jchesterpivotal

Hi @jchesterpivotal thanks for reaching out. We haven't picked up this feature yet but will be doing a round of research on scripting soon. The goal of the research is to understand our different user personas - especially app developers/operators who script against the CLI. We'd like to understand these various personas so that, as a product, the CLI can deliver value in a more targeted manner. We hope to reach out to the Community soon with a survey.

In regards to v7 progress. This is the tracker for the project. It's the best glimpse into our upcoming epics but may not provide the quick overview you might be looking for. To date, we are still working on converting V2 API resources into V3 (stacks, buildpacks, and we hope to tackle feature flags next), and we are also targeting updating cf push such that it is backed by V3 endpoints and server side manifests. Please do not hesitate to reach out if you have any questions regarding any of this.

abbyachau avatar Jan 31 '19 02:01 abbyachau

Thanks, @abbyachau! I'm excited to see the v3 API +v7 CLI coming together (codename: V10?).

jchesterpivotal avatar Jan 31 '19 14:01 jchesterpivotal

Further evidence: https://github.com/cloudfoundry/cli/issues/1585#issuecomment-468837597

abbyachau avatar Mar 02 '19 20:03 abbyachau

Hey @andy-paine it was good speaking at Summit. If you (and others) could list the commands that you would like us to ideally prioritise first if we implemented this feature, that would be helpful.

abbyachau avatar Sep 18 '19 18:09 abbyachau

@rjain-pivotal any feedback on a wish list of commands that you would love to see support --json first?

abbyachau avatar Oct 23 '19 22:10 abbyachau

I'll vote: env, service, and service-key Context

As a Cody When I need to create a service for my app I want programmatically read the service configuration So that I can configure another app, in a disconnected space, org, foundation or legacy system, to use the same service.

Concrete example we are using RabbitMQ as a way to invert control, and allow an app inside a firewall to obtain workloads from a publicly hosted app. This avoids any ingress rules. The app running inside the firewall needs to see the latest configuration from the external app's Rabbit service

squeedee avatar Mar 23 '20 15:03 squeedee

cf target command to get the GUID for your current org and space.

norman-abramovitz avatar Mar 23 '20 16:03 norman-abramovitz

I mentioned service-key but you may consider it a different issue, it produces json, but also a message, on stdout:

✓ master → cf service-key self-service-queue self-service-queue-worker-key 2>/dev/null
Getting key self-service-queue-worker-key for service instance self-service-queue as [email protected]...

{
 "http_api_uri": "https://<redacted>",
 "uri": "<redacted>"
}

squeedee avatar Mar 23 '20 16:03 squeedee

Any progress on this one? log-cache plugin for example already has this feature (--json switch) which makes it 100 times better fit to be part of scripts.

mvadu avatar Aug 07 '20 21:08 mvadu

Would it make sense to create a PR that improves:

https://github.com/cloudfoundry/cli/blob/main/cf/commands/servicekey/service_key.go#L73

? And the related Unit Tests?

gregorwolf avatar Jul 13 '22 16:07 gregorwolf