apt-pkg-native/examples/policy.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

2017-07-13 16:44:14 +03:00
extern crate apt_pkg_native;
use std::env;
use apt_pkg_native::simple;
use apt_pkg_native::Cache;
fn main() {
2017-07-13 17:37:35 +03:00
let pkg = env::args().nth(1).expect(
"usage: first argument: package name",
);
let arch = env::args().nth(2);
2017-07-13 16:44:14 +03:00
let mut cache = Cache::get_singleton();
let mut found = match arch {
Some(arch) => cache.find_by_name_arch(pkg.as_str(), arch.as_str()),
2017-07-13 17:37:35 +03:00
None => cache.find_by_name(pkg.as_str()),
};
2017-07-13 16:44:14 +03:00
if let Some(view) = found.next() {
println!("{}:{}:", view.name(), view.arch());
2017-07-13 17:37:17 +03:00
2017-07-13 17:37:35 +03:00
let installed_version = view.current_version().unwrap_or_else(
|| "(none)".to_string(),
);
println!(" Installed: {}", installed_version);
2017-07-13 17:37:35 +03:00
println!(
" Candidate: {}",
view.candidate_version().unwrap_or_else(
|| "(none)".to_string(),
)
);
2017-07-13 17:37:17 +03:00
println!(" Version table:");
for simple::VersionOrigins { version, origins } in
view.versions().map(simple::VersionOrigins::new)
{
2017-07-13 17:31:11 +03:00
println!(" {} {} {}",
if version.version == installed_version { "***" } else { " " },
2017-07-13 17:31:11 +03:00
version.version,
version.priority,
);
2017-07-13 17:37:17 +03:00
for origin in origins {
println!(" {:4} {}", "XXX", origin);
}
}
} else {
println!("unrecognised package: {}", pkg);
2017-07-13 16:44:14 +03:00
}
}