Skip to content

Conversation

@blgm
Copy link
Member

@blgm blgm commented Feb 11, 2026

The "cf service-key" command outputs JSON, apart from a standard header which most CF commands print out. As a result, it's very common to see code like:

cf service-key "$SERVICE_INSTANCE_NAME" $KEY_NAME | tail -n +2

This removes the header from the output leaving just JSON. Search GitHub and you'll see pages of hits.

Rather than forcing script users to chop of the header, risking issues with errors in pipes, etc... It woudld be better just to print the correct output in the first place. This commit: adds a "--json" flag which outputs JSON only. It follows the convention of "--guid" to supress warnings too (unless there an error). In practice the endpoints in question do not produce warnings, so it makes no practical difference.

Thank you for contributing to the CF CLI! Please read the following:

  • Please make sure you have implemented changes in line with the contributing guidelines
  • We're not allowed to accept any PRs without a signed CLA, no matter how small.
    If your contribution falls under a company CLA but your membership is not public, expect delays while we confirm.
  • All new code requires tests to protect against regressions.
  • Contributions must be made against the appropriate branch. See the contributing guidelines
  • Contributions must conform to our style guide. Please reach out to us if you have questions.

Note: Please create separate PR for every branch (main and v8) as needed.

Description of the Change

We must be able to understand the design of your change from this description.
Keep in mind that the maintainer reviewing this PR may not be familiar with or
have worked with the code here recently, so please walk us through the concepts.

Why Is This PR Valuable?

What benefits will be realized by the code change? What users would want this change? What user need is this change addressing?

Applicable Issues

List any applicable GitHub Issues here

How Urgent Is The Change?

Is the change urgent? If so, explain why it is time-sensitive.

Other Relevant Parties

Who else is affected by the change?

The "cf service-key" command outputs JSON, apart from a standard
header which most CF commands print out. As a result, it's very
common to see code like:
```
cf service-key "$SERVICE_INSTANCE_NAME" $KEY_NAME | tail -n +2
```
This removes the header from the output leaving just JSON.
Search GitHub and you'll see pages of hits.

Rather than forcing script users to chop of the header, risking
issues with errors in pipes, etc... It woudld be better just
to print the correct output in the first place. This commit:
adds a "--json" flag which outputs JSON only. It follows the
convention of "--guid" to supress warnings too (unless there
an error). In practice the endpoints in question do not produce
warnings, so it makes no practical difference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant