[−][src]Crate cargo_metadata
Structured access to the output of cargo metadata
Usually used from within a cargo-*
executable
Examples
With std::env::args()
:
let mut args = std::env::args().skip_while(|val| !val.starts_with("--manifest-path")); let mut cmd = cargo_metadata::MetadataCommand::new(); let manifest_path = match args.next() { Some(ref p) if p == "--manifest-path" => { cmd.manifest_path(args.next().unwrap()); } Some(p) => { cmd.manifest_path(p.trim_left_matches("--manifest-path=")); } None => {} }; let _metadata = cmd.exec().unwrap();
With docopt
:
const USAGE: &str = " Cargo metadata test function Usage: cargo_metadata [--manifest-path PATH] "; #[derive(Debug, Deserialize)] struct Args { arg_manifest_path: Option<String>, } let args: Args = Docopt::new(USAGE) .and_then(|d| d.deserialize()) .unwrap_or_else(|e| e.exit()); let mut cmd = cargo_metadata::MetadataCommand::new(); if let Some(path) = args.arg_manifest_path { cmd.manifest_path(path); } let _metadata = cmd.exec().unwrap();
With clap
:
let matches = clap::App::new("myapp") .arg( clap::Arg::with_name("manifest-path") .long("manifest-path") .value_name("PATH") .takes_value(true), ) .get_matches(); let mut cmd = cargo_metadata::MetadataCommand::new(); if let Some(path) = matches.value_of("manifest-path") { cmd.manifest_path(path); } let _metadata = cmd.exec().unwrap();
With structopt
:
#[derive(Debug, StructOpt)] struct Opt { #[structopt(name = "PATH", long="manifest-path", parse(from_os_str))] manifest_path: Option<PathBuf>, } let opt = Opt::from_args(); let mut cmd = cargo_metadata::MetadataCommand::new(); if let Some(path) = opt.manifest_path { cmd.manifest_path(path); } let _metadata = cmd.exec().unwrap();
Pass features flags
use cargo_metadata::{MetadataCommand, CargoOpt}; let _metadata = MetadataCommand::new() .manifest_path("./Cargo.toml") .features(CargoOpt::AllFeatures) .exec() .unwrap();
Structs
Dependency | A dependency of the main crate |
Error | The Error type. |
Metadata | Starting point for metadata returned by |
MetadataCommand | A builder for configurating |
Node | A node in a dependencies graph |
NodeDep | A dependency in a node |
Package | A crate |
PackageId | An "opaque" identifier for a package.
It is possible to inspect the |
Resolve | A dependency graph |
Target | A single target (lib, bin, example, ...) provided by a crate |
Enums
CargoOpt | Cargo features flags |
DependencyKind | Dependencies can come in three kinds |
ErrorKind | The kind of an error. |
Type Definitions
Result | Convenient wrapper around |