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

Subcommand dependencies #1225

Closed
wants to merge 3 commits into from
Closed

Conversation

dan-t
Copy link

@dan-t dan-t commented Jan 25, 2015

The subcommand dependencies outputs the resolved dependencies
of a project, the concrete used versions including overrides,
in a TOML format.

dan-t added 3 commits January 25, 2015 19:15
The subcommand dependencies outputs the resolved dependencies
of a project, the concrete used versions including overrides,
in a TOML format.
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@alexcrichton
Copy link
Member

Thanks for the PR! This is definitely an important part of Cargo's story in easy and amenable tooling. Some things to think about:

  • Cargo was actually designed with this sort of use case in mind. Each method of each subcommand returns Option<T> which actually requires T: Encodable. The idea was that each subcommand returned something encodable which was then encoded onto stdout as JSON (or any encodable format really). Along those lines, I think that the custom emission in TOML-format code should probably be represented in terms of toml::encode_str somehow. Additionally, this may want to re-hook-up the machinery to auto-print the information to stdout (I think I butchered it in a refactor awhile ago).
  • This is certainly a pretty hot subcommand, there's a lot you can do with dependencies! One may want to, for example, add dependencies, remove them, modify them, etc. Either that or also print out specific metadata about one dependency (perhaps more detailed than what's printed here).

In general there's a lot of ways a subcommand like this can go, and I don't think we've truly fleshed out our "subcommand producing machine-readable data" story just yet. For example we may want to standardize on an output format flag to output in e.g. TOML or JSON format. What are your thoughts on this?

@dan-t
Copy link
Author

dan-t commented Feb 7, 2015

The first thing is, if it could make sense to have a e.g. ResolvedDependency type:

type Name = String;
struct ResolvedDependency {
    name: Name,
version: Version,
package_id: PackageId,
dependencies: Vec<Name>
}

And then a low level function like:

type ResolvedDependencies = Vec<ResolvedDependency>;
pub fn resolve_dependencies(manifest: &Path) -> CargoResult<ResolvedDependencies>

The dependency output could then be based on this function.

If the dependencies subcommand should be used for several operations
with dependencies, then one option could be to name the dependencies
output command just cargo output-dependencies or to use a sub-subcommand
scheme like cargo dependencies output.

Regarding the standardization of subcommands outputing machine-readable
data, then having a default format could make sense - it's questionable
if the default format should be configurable - and then have an option
like --format=TOML or --format=JSON to be able to explicitely
specify the output format.

@dan-t
Copy link
Author

dan-t commented Mar 26, 2015

The implementation of this subcommand is now continued in #1434.

@dan-t dan-t closed this Mar 26, 2015
matklad added a commit to matklad/cargo that referenced this pull request Jan 25, 2016
bors added a commit that referenced this pull request Jan 25, 2016
Most of the work was done by @dan-t in #1225 and by @winger in #1434

Fixes #2193

I failed to properly rebase previous attempts so I just salvaged this from bits and pieces.

@alexcrichton are you sure that the default format should be TOML? I think that TOML is more suitable for humans, and JSON is better (at the moment at least) for tools. Maybe we should default to ~~TOML~~ JSON?
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.

3 participants