Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON Export for App #918

Open
mitsuhiko opened this issue Mar 26, 2017 · 11 comments
Open

Add JSON Export for App #918

mitsuhiko opened this issue Mar 26, 2017 · 11 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@mitsuhiko
Copy link
Contributor

It would be great to be able to export the app with all subcommands, options and args to JSON (or something similar) so documentation tools can then pick up on it and make documentation pages.

@kbknapp
Copy link
Member

kbknapp commented Mar 26, 2017

Great suggestion, I'd love this. I have it on the back burner to add serde impls, specifically so we could get YAML and JSON. This will probably come out in the 3.x release which I keep hoping is right on the horizon...but then my day job goes and monopolizes my time. Hopefully soonish!

@kbknapp kbknapp added A-builder Area: Builder API C: args E-hard Call for participation: Experience needed to fix: Hard / a lot labels Mar 26, 2017
@mitsuhiko
Copy link
Contributor Author

I was toying around with making a soft version of this that just spits out some json but it's not clear on what basis this could be implemented. I was taking the completion code as a reference (the zsh one spits out most of the info I need) but it uses lots of internal APIs.

I wonder if it would make sense to base the completion code on an abstraction that could become public and then also be used for other exporting.

@kbknapp
Copy link
Member

kbknapp commented Mar 26, 2017

I bet providing Debug impls would get us 90% of the way there. Not full on JSON, but close. src/args/arg_builder/valued.rs would need a manual impl because of the validator[_os], but everything else could probably be derived

@kbknapp
Copy link
Member

kbknapp commented Mar 26, 2017

Also I should also add, providing serde::Serialize for either YAML or JSON (or really any target) isn't a breaking change, and doesn't need to wait for 3.x. The only part that would be "breaking" is using serde for the Deserialize for YAML. Although, even then not technically breaking because the API used would be different than the current App::from_yaml.

@kbknapp
Copy link
Member

kbknapp commented Mar 26, 2017

So actually providing a JSON/YAML serialization doesn't seem to be that hard, and is pretty straight forward. Maybe I can knock it out this week.

I will want the serde{_json._yaml} crates to be optional and behind a feature flag. And I want to keep the minimum version of Rust 1.11 if possibe (so no #[derive(..)] or ?) for the time being.

@mitsuhiko
Copy link
Contributor Author

You could keep serde internal for now and just provide an export to JSON / YAML function that directly writes to a writer.

@kbknapp kbknapp added this to the serde milestone Mar 27, 2017
@kbknapp kbknapp mentioned this issue Aug 22, 2017
87 tasks
@kbknapp kbknapp removed the W: 2.x label Jul 22, 2018
@pksunkara pksunkara removed the W: 3.x label May 26, 2021
@pksunkara pksunkara removed this from the serde milestone May 26, 2021
@pksunkara
Copy link
Member

Blocked by dtolnay/serde-yaml#94

@epage
Copy link
Member

epage commented Jul 20, 2021

Like with #853, #1041 could help with the lifetime blocker

@MikailBag
Copy link

MikailBag commented Jul 20, 2021

AFAIU, serde-yaml lifetime limitations are not really blockers: one can serialize to JSON at first, and then serialize serde_json::Value to YAML.

Also, JSON seems to be subset of YAML, so json-serialized string can be interpreted as yaml.

@epage
Copy link
Member

epage commented Jul 20, 2021

Forgot which issue I was on, in general, exporting isn't blocked on the lifetime issue, only importing and only for yaml.

I'm assuming we'd want to solve these several issues (#853, #1630, this one) together, providing a single serialization/deserialization experience and not have serde for most types and then a special case for deserializing from yaml, which would make the lifetime issue a blocker.

@epage epage added A-help Area: documentation, including docs.rs, readme, examples, etc... and removed A-builder Area: Builder API labels Dec 8, 2021
@epage
Copy link
Member

epage commented Dec 8, 2021

How much would #2914 help in this case?

The idea would be that help generation is split into the generator and formatter. This would allow user-defined formatters, like man pages. Would that work for this case?

@epage epage removed C: args labels Dec 8, 2021
@epage epage added C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing and removed T: new feature E-hard Call for participation: Experience needed to fix: Hard / a lot labels Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

5 participants