generated from EmbarkStudios/opensource-template
/
graph.rs
70 lines (59 loc) 路 1.54 KB
/
graph.rs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use clap::Parser;
use std::fmt;
/// Simple program to greet a person
#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
manifest_path: String,
#[arg(long)]
features: Vec<String>,
#[arg(long)]
all_features: bool,
#[arg(long)]
no_default_features: bool,
#[arg(long)]
no_dev: bool,
}
pub struct Simple {
id: krates::Kid,
//features: HashMap<String, Vec<String>>,
}
pub type Graph = krates::Krates<Simple>;
impl From<krates::cm::Package> for Simple {
fn from(pkg: krates::cm::Package) -> Self {
Self {
id: pkg.id,
//features: pkg.fee
}
}
}
impl fmt::Display for Simple {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.id.repr)
}
}
fn main() {
let args = Args::parse();
let cmd = {
let mut cmd = krates::Cmd::new();
if args.all_features {
cmd.all_features();
}
if args.no_default_features {
cmd.no_default_features();
}
if !args.features.is_empty() {
cmd.features(args.features);
}
cmd.manifest_path(args.manifest_path);
cmd
};
let mut builder = krates::Builder::new();
if args.no_dev {
builder.ignore_kind(krates::DepKind::Dev, krates::Scope::All);
}
let graph: Graph = builder.build(cmd, krates::NoneFilter).unwrap();
let dot = krates::petgraph::dot::Dot::new(graph.graph()).to_string();
use std::io::Write;
std::io::stdout().write_all(dot.as_bytes()).unwrap();
}