-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
30 lines (25 loc) · 1.03 KB
/
main.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
extern crate cargo_update;
extern crate git2;
extern crate json;
use cargo_update::ops::{find_package_data, get_index_path};
use git2::Repository;
use std::path::Path;
fn main() {
// @todo how can I get cargo's home dir from Rust?
let cargo_dir = Path::new("/home/klausi/.cargo");
let registry = get_index_path(cargo_dir);
let registry_repo = Repository::open(®istry).unwrap();
let latest_registry = registry_repo.revparse_single("origin/master").unwrap();
// @todo read package name from Cargo.toml.
let package_data = find_package_data("libz-sys", &latest_registry.as_commit().unwrap().tree().unwrap(), ®istry_repo).unwrap();
let json_string = String::from_utf8(package_data).unwrap();
let new_data: String = json_string.lines()
.map(|line| {
let mut parsed = json::parse(line).unwrap();
// @todo Read links section from Cargo.toml
parsed["links"] = "z".into();
parsed.dump() + "\n"
})
.collect();
println!("{}", new_data);
}