mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.48k stars 473 forks source link

Rework CLI interface #144

Open grische opened 1 month ago

grische commented 1 month ago

This reworks the CLI of the tool to allow specifiying or overriding the function parameters of the tool on the command-line.

To make this feasible, I needed named parameters for the jsonToGo() function. In order to not break existing integrations, I named the new function jsonToGov2(). This is currently fully backwards compatible (as the tests show).

@mholt What do you think about the change? Do you have a better name in mind? This is particular about the first commit 4fad829245d692386fc4a3a24b75e93f9c55a941

The other commits are just improvements on the CLI, as well as a backwards-compatibility integration of v1: 0f504683d468d866c3939f2ea4358b4c2b35463f

grische commented 1 month ago

If you prefer a single file solution (because someone has embedded this into their project using a raw GitHub link to the file), we can of course also create a wrapper function that checks if the second argument is type object and then goes the v2 route, else goes the v1 route.

Let me know what you think.