apt-pkg-native/examples/policy.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

2017-07-13 16:44:14 +03:00
use std::env;
2018-04-12 22:35:08 +03:00
use apt_pkg_native::simple;
2018-12-17 22:04:09 +03:00
use apt_pkg_native::Cache;
2017-07-13 16:44:14 +03:00
fn main() {
2017-11-17 12:03:38 +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
2018-12-17 22:04:09 +03:00
let installed_version = view
.current_version()
2017-11-17 12:03:38 +03:00
.unwrap_or_else(|| "(none)".to_string());
println!(" Installed: {}", installed_version);
2017-07-13 17:37:35 +03:00
println!(
" Candidate: {}",
2017-11-17 12:03:38 +03:00
view.candidate_version()
.unwrap_or_else(|| "(none)".to_string(),)
2017-07-13 17:37:35 +03:00
);
2017-07-13 17:37:17 +03:00
println!(" Version table:");
for simple::VersionOrigins { version, origins } in
view.versions().map(simple::VersionOrigins::new)
{
2017-11-17 12:03:38 +03:00
println!(
" {} {} {}",
if version.version == installed_version {
"***"
} else {
" "
},
version.version,
version.priority,
2017-07-13 17:31:11 +03:00
);
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
}
}