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

Add JSON output capabilities #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add JSON output capabilities #21

wants to merge 1 commit into from

Conversation

Twey
Copy link

@Twey Twey commented Oct 17, 2017

I needed this to be able to output JSON for parsing elsewhere.

@@ -50,6 +53,7 @@ Options:
--charset CHARSET Set the character set to use in output. Valid
values: utf8, ascii [default: utf8]
-f, --format FORMAT Format string for printing dependencies
-j, --json Print a JSON representation of the tree
Copy link
Owner

Choose a reason for hiding this comment

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

I think it'd make sense to match the --output-format flag that Cargo uses, and make the JSON representation compatible with that.

@@ -317,6 +330,13 @@ struct Graph<'a> {
nodes: HashMap<&'a PackageId, NodeIndex>,
}

#[derive(Debug, Serialize, Deserialize)]
Copy link
Owner

Choose a reason for hiding this comment

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

No need to implement Deserialize I don't think.

@@ -214,6 +219,14 @@ fn real_main(flags: Flags, config: &Config) -> CliResult {
flags.flag_all);
println!("");
}
} else if flags.flag_json {
println!("{}", serde_json::to_string_pretty(
&graph_to_tree(package.package_id(),
Copy link
Owner

Choose a reason for hiding this comment

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

It seems a bit strange that this mode would ignore a bunch of the flags the other modes respect.

@sfackler
Copy link
Owner

Have you taken a look at cargo metadata? That's the main interface for interacting programmatically with Cargo.

@Twey
Copy link
Author

Twey commented Oct 20, 2017

Unfortunately cargo metadata doesn't output any information on resolved features, which I need, and also doesn't output a tree, which is handy for my use-case. While I could munge it into the right format, it seemed like a better option to reuse cargo-tree, since that's basically what it does already. I don't mind keeping this local if you don't want machine-friendly formats in cargo-tree, though.

@sfackler
Copy link
Owner

What do you mean by resolved features?

I would kind of like to keep this project focused on user-facing output.

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