Skip to content

Conversation

@fgebhart
Copy link
Contributor

Description

This change formats the output of "Copy as cURL" for the sake of readability. It changes it from a single line to multi line and applies indentation for a nested json payload. This was discussed in and closes #678 .

Note, that I'm proposing to change CurlBuilder.command to CurlBuilder.gorups of commands. Inserting new lines is then much easier and allows to avoid having to implement a heuristic like I tried here. Let me know what you prefer.

Thanks for the hints 👍

Known Risks

The output curl is valid as before and should works as before.

QA

I adapted existing tests and added a new test to provide an example for a largish json payload. Taken from #678 .

Checklist

  • Have you read CONTRIBUTING.md already?
  • Did you update CHANGELOG.md?
    • Only user-facing changes belong in the changelog. Internal changes such as refactors should only be included if they'll impact users, e.g. via performance improvement.
  • Did you remove all TODOs?
    • If there are unresolved issues, please open a follow-on issue and link to it in a comment so future work can be tracked

* iterate over command groups and add new lines
* prettify json payload with proper indentation
* apply newlines only in case of curl command being above threshold
* adapt existing and add new test
* closes LucasPickering#678
@LucasPickering
Copy link
Owner

Thanks for your work on this! I just pushed a commit with a few tweaks:

  • Tweaked the changelog message
  • Simplified some of my old logic (replaced Cow<'static str> with String. It was a very unnecessary optimization)
  • Moved the --url flag onto the first line. The beginning curl -XMETHOD will always be short so it can fit the URL
  • Removed the test logic that checks the line length, in favor of hardcoding the formatted version

@LucasPickering LucasPickering enabled auto-merge (rebase) December 21, 2025 19:45
@LucasPickering LucasPickering force-pushed the multiline-curl-command-output-using-groups branch from d4d29b9 to 44c7f14 Compare December 22, 2025 09:33
@LucasPickering LucasPickering merged commit 8797321 into LucasPickering:master Dec 22, 2025
34 checks passed
@fgebhart
Copy link
Contributor Author

awesome, thanks for the positive feedback and integrating this feature - will enjoy slumber now even more 🚀

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.

Improve readability of the output of "Copy as cURL"

2 participants