Struct guppy::MetadataCommand
source · pub struct MetadataCommand { /* private fields */ }
Expand description
A builder for configuring cargo metadata
invocations.
This is the most common entry point for constructing a PackageGraph
.
§Examples
Build a PackageGraph
for the Cargo workspace in the current directory:
use guppy::MetadataCommand;
use guppy::graph::PackageGraph;
let mut cmd = MetadataCommand::new();
let package_graph = PackageGraph::from_command(&mut cmd);
Implementations§
source§impl MetadataCommand
impl MetadataCommand
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a default cargo metadata
command builder.
By default, this will look for Cargo.toml
in the ancestors of this process’s current
directory.
sourcepub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the path to the cargo
executable.
If unset, this will use the $CARGO
environment variable, or else cargo
from $PATH
.
sourcepub fn manifest_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn manifest_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the path to Cargo.toml
.
By default, this will look for Cargo.toml
in the ancestors of the current directory. Note
that this doesn’t need to be the root Cargo.toml
in a workspace – any member of the
workspace is fine.
sourcepub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the current directory of the cargo metadata
process.
By default, the current directory will be inherited from this process.
sourcepub fn no_deps(&mut self) -> &mut Self
pub fn no_deps(&mut self) -> &mut Self
Output information only about the workspace and do not fetch dependencies.
For full functionality, cargo metadata
should be run without --no-deps
, so that guppy
knows about third-party crates and dependency edges. However, guppy
supports a “light”
mode if --no-deps
is run, in which case the following limitations will apply:
- dependency queries will not work
- there will be no information about non-workspace crates
Constructing a graph with this option can be several times faster than the default.
sourcepub fn other_options(
&mut self,
options: impl IntoIterator<Item = impl Into<String>>
) -> &mut Self
pub fn other_options( &mut self, options: impl IntoIterator<Item = impl Into<String>> ) -> &mut Self
Arbitrary flags to pass to cargo metadata
. These will be added to the end of the
command invocation.
Note that guppy
internally:
- uses
--format-version 1
as its metadata format. - passes in
--all-features
, so thatguppy
has a full view of the dependency graph.
Attempting to override either of those options may lead to unexpected results.
sourcepub fn cargo_command(&self) -> Command
pub fn cargo_command(&self) -> Command
sourcepub fn exec(&self) -> Result<CargoMetadata, Error>
pub fn exec(&self) -> Result<CargoMetadata, Error>
Runs the configured cargo metadata
and returns a deserialized CargoMetadata
.
sourcepub fn build_graph(&self) -> Result<PackageGraph, Error>
pub fn build_graph(&self) -> Result<PackageGraph, Error>
Runs the configured cargo metadata
and returns a parsed PackageGraph
.
Trait Implementations§
source§impl Clone for MetadataCommand
impl Clone for MetadataCommand
source§fn clone(&self) -> MetadataCommand
fn clone(&self) -> MetadataCommand
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MetadataCommand
impl Debug for MetadataCommand
source§impl Default for MetadataCommand
impl Default for MetadataCommand
source§fn default() -> MetadataCommand
fn default() -> MetadataCommand
source§impl<'a> TryFrom<&'a MetadataCommand> for PackageGraph
impl<'a> TryFrom<&'a MetadataCommand> for PackageGraph
source§impl TryFrom<MetadataCommand> for PackageGraph
impl TryFrom<MetadataCommand> for PackageGraph
Although consuming a MetadataCommand
is not required for building a PackageGraph
, this impl
is provided for convenience.