1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::path;
#[derive(Default, Clone, Debug, PartialEq, Eq, structopt::StructOpt)]
#[non_exhaustive]
pub struct Manifest {
#[structopt(long, name = "PATH", parse(from_os_str))]
pub manifest_path: Option<path::PathBuf>,
}
#[cfg(feature = "cargo_metadata")]
impl Manifest {
pub fn metadata(&self) -> cargo_metadata::MetadataCommand {
let mut c = cargo_metadata::MetadataCommand::new();
if let Some(ref manifest_path) = self.manifest_path {
c.manifest_path(manifest_path);
}
c
}
}
#[cfg(test)]
mod test {
use super::*;
#[cfg(feature = "cargo_metadata")]
#[test]
fn metadata_with_path() {
let manifest = Manifest {
manifest_path: Some(path::PathBuf::from("tests/fixtures/simple/Cargo.toml")),
};
let metadata = manifest.metadata();
metadata.exec().unwrap();
}
#[cfg(feature = "cargo_metadata")]
#[test]
fn metadata_without_path() {
let cwd = path::PathBuf::from("tests/fixtures/simple");
let manifest = Manifest {
manifest_path: None,
};
let mut metadata = manifest.metadata();
metadata.current_dir(cwd).exec().unwrap();
}
}