apt-pkg-native/examples/policy.rs

38 lines
1.2 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() {
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()),
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
let installed_version = view.current_version().unwrap_or_else(|| "(none)".to_string());
println!(" Installed: {}", installed_version);
2017-07-13 17:37:17 +03:00
println!(" Candidate: {}", view.candidate_version().unwrap_or_else(|| "(none)".to_string()));
println!(" Version table:");
2017-07-13 17:37:17 +03:00
for version in view.versions().map(simple::Version::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
2017-07-13 17:31:11 +03:00
println!(" TODO: urls");
}
} else {
println!("unrecognised package: {}", pkg);
2017-07-13 16:44:14 +03:00
}
}