Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Add ability to stream response to file #25

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

iowillhoit
Copy link
Contributor

What does this PR do?

  • Adds a stream to file flag and behavior
  • Allows an empty body (similar to curl)
  • Splits headers on the first :. This allows for :s to exist in the header value

Note: "ignore whitespace" will make the diff cleaner

Testing

You can test this by running a report and accepting an xlxs file (api docs)

Example command would be:
sf org api '/services/data/v61.0/analytics/reports/00OEE000001ZdM52AK' -o gus -X POST -H "Accept:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" --body "" -S "report.xlsx"

Confirm the file opens in Excel, Numbers, Google Sheets, etc

What issues does this PR fix or reference?

@W-16215223@

helpValue: 'Example: report.xlsx',
char: 'S',
exclusive: ['include'],
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a better name for this flag, let me know. The S character is used by curl for "show error"

body: Flags.string({
summary:
'The file to use as the body for the request (use "-" to read from standard input).',
'The file to use as the body for the request (use "-" to read from standard input, use "" for an empty body).',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches curl

const split = header.split(':');
if (split.length !== 2) {
const [key, ...rest] = header.split(':')
const value = rest.join(':').trim();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was copying headers from chrome dev tools and notice that "Origin:https://gus.lightning.force.com" would not parse correctly because of the additional :

@cristiand391
Copy link
Owner

QA notes:

--stream-to-file saves res.body to file
✅ can set empty body
✅ can't use --include with --stream-to-file

@cristiand391 cristiand391 merged commit 2d2ee4d into cristiand391:main Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants