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

want volta list --format=json #550

Open
mcarifio opened this issue Sep 16, 2019 · 10 comments · May be fixed by #1155
Open

want volta list --format=json #550

mcarifio opened this issue Sep 16, 2019 · 10 comments · May be fixed by #1155

Comments

@mcarifio
Copy link
Contributor

Would be nice to have volta list --format=json with a json schema similar to npm's. I will sometimes use this format with jq or similar "pick out" useful information. Low priority item.

@chriskrycho
Copy link
Contributor

Thanks for flagging it up – we'd like this as well, and it's actually probably a relatively easy lift, just (as you noted) a lower priority. If someone out there wants to implement it, however, it's actually far and away the easiest of the list --format=... variants to implement, because all it actually requires is using the existing logic for list and Serde definitions for the output types.

@musikid
Copy link

musikid commented Oct 10, 2019

I can take a look at it!

@charlespierce
Copy link
Contributor

@musikid That would be great! I haven't dug in too deeply, but I imagine you can leverage serde_json to generate the actual JSON output. Let us know if you run into any issues or have questions!

@musikid
Copy link

musikid commented Nov 1, 2019

Hi!
I tried to implement this feature for a while now but I abandoned and forgot it because I faced a strange problem that I haven't been able to solve.
I tried in first to derive the Serialize trait but it failed. And when I tried to implement manually the trait, I get the same error.
command::list::_IMPL_SERIALIZE_FOR_Source::_serde::Serialize is not implemented for semver::version::Version
Do you have any clue about it ?

@charlespierce
Copy link
Contributor

Hi @musikid! I think I understand that error: It looks like the Serialize trait, which is what serde needs to perform the serialization, isn't implemented for the Version struct, which is provided by semver. Unfortunately, due to Rust's orphaning rules, we can't just make our own with:

impl Serialize for Version {}

However, I do know that Version implements Display, as we use that often throughout the Volta code, so one solution would be for your data structure to use String everywhere you were previously using Version. Then when creating an instance, you can call .to_string() on every one of the Version values to convert it into a string. Serde knows how to handle Strings, so then it should be able to derive the Serialize trait correctly.

@musikid
Copy link

musikid commented Nov 1, 2019

What I forget to precise first is that Version actually implement the Serialize but I didn't understand why it gives that error. Nevermind, I just realized that the trait is just part of the serde feature and this was the reason why it didn't appear.

@musikid
Copy link

musikid commented Nov 1, 2019

Thanks @charlespierce for the help!

@chriskrycho
Copy link
Contributor

Hey @musikid, how's this coming along? No worries if you're unable to finish it; just figured I'd check in!

@musikid
Copy link

musikid commented Jan 9, 2020

I almost finished it. I just need to write proper tests and it should be ready! Sorry for the time it took, I had some important things to deal with so I wasn't able to do it.

@chriskrycho
Copy link
Contributor

@musikid no need to apologize, not even a little! Was just checking in as I was going through the open issues to see what their status is. Feel free to open a Draft PR and we can give you early feedback on it!

@charlespierce charlespierce added this to Features in Backlog Jun 11, 2020
@alexlafroscia alexlafroscia linked a pull request Feb 5, 2022 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Features
Development

Successfully merging a pull request may close this issue.

4 participants