manager: versions: unify printing

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-11-11 18:30:19 +01:00
parent c100fe9108
commit 294466ee61
1 changed files with 18 additions and 50 deletions

View File

@ -381,59 +381,27 @@ async fn report() -> Result<Value, Error> {
)] )]
/// List package versions for important Proxmox Backup Server packages. /// List package versions for important Proxmox Backup Server packages.
async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> { async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> {
let output_format = param.get("output-format"); let output_format = get_output_format(&param);
if !verbose && output_format.is_none() { let mut packages = if verbose {
let pkg_version = format!( crate::api2::node::apt::get_versions()?
"{}.{}",
crate::api2::version::PROXMOX_PKG_VERSION,
crate::api2::version::PROXMOX_PKG_RELEASE
);
let running_kernel = nix::sys::utsname::uname().release().to_owned();
println!(
"proxmox-backup-server/{} (running kernel: {})",
pkg_version, running_kernel
);
return Ok(Value::Null);
}
let mut packages = crate::api2::node::apt::get_versions()?;
if let Some(output_format) = output_format {
if let Some(output_format) = output_format.as_str() {
let options = TableFormatOptions::default();
format_and_print_result_full(
&mut packages,
&crate::api2::node::apt::API_RETURN_SCHEMA_GET_VERSIONS,
output_format,
&options,
);
}
} else { } else {
// pveversion style print // TODO: slice first element out in a nicer way?
let packages: Vec<APTUpdateInfo> = serde_json::from_value(packages)?; let packages = crate::api2::node::apt::get_versions()?;
for pkg in packages { let packages = packages.as_array().unwrap();
let mut version = "not correctly installed"; Value::Array(vec![packages[0].to_owned()])
if !pkg.old_version.is_empty() && &pkg.old_version != "unknown" { };
version = &pkg.old_version;
}
if let Some(extra_info) = pkg.extra_info { let options = default_table_format_options()
println!( .disable_sort()
"{}: {} ({})", .noborder(true) // just not helpfull for version info which gets copy pasted often
pkg.package, .column(ColumnConfig::new("Package"))
version, .column(ColumnConfig::new("Version"))
extra_info .column(ColumnConfig::new("ExtraInfo").header("Extra Info"))
); ;
} else { let schema = &crate::api2::node::apt::API_RETURN_SCHEMA_GET_VERSIONS;
println!(
"{}: {}", format_and_print_result_full(&mut packages, schema, &output_format, &options);
pkg.package,
version,
);
}
}
}
Ok(Value::Null) Ok(Value::Null)
} }