From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] apt: use typed response for get_versions
Date: Thu, 12 Nov 2020 10:12:54 +0100 [thread overview]
Message-ID: <20201112091254.29059-1-s.reiter@proxmox.com> (raw)
In-Reply-To: <36cbccc4-340b-933b-63d7-921bc332a25b@proxmox.com>
...and cleanup get_versions for manager CLI.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
No need to return an untyped Value, especially if we want to further work with
it, so how about this for a cleanup?
src/api2/node/apt.rs | 4 ++--
src/bin/proxmox-backup-manager.rs | 10 ++--------
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index 500b2309..765ea525 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -261,7 +261,7 @@ fn apt_get_changelog(
},
)]
/// Get package information for important Proxmox Backup Server packages.
-pub fn get_versions() -> Result<Value, Error> {
+pub fn get_versions() -> Result<Vec<APTUpdateInfo>, Error> {
const PACKAGES: &[&str] = &[
"ifupdown2",
"libjs-extjs",
@@ -350,7 +350,7 @@ pub fn get_versions() -> Result<Value, Error> {
}
}
- Ok(json!(packages))
+ Ok(packages)
}
const SUBDIRS: SubdirMap = &[
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index 84ec0148..80e699f1 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -383,14 +383,8 @@ async fn report() -> Result<Value, Error> {
async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> {
let output_format = get_output_format(¶m);
- let mut packages = if verbose {
- crate::api2::node::apt::get_versions()?
- } else {
- // TODO: slice first element out in a nicer way?
- let packages = crate::api2::node::apt::get_versions()?;
- let packages = packages.as_array().unwrap();
- Value::Array(vec![packages[0].to_owned()])
- };
+ let packages = crate::api2::node::apt::get_versions()?;
+ let mut packages = json!(if verbose { &packages[..] } else { &packages[0..1] });
let options = default_table_format_options()
.disable_sort()
--
2.20.1
next prev parent reply other threads:[~2020-11-12 9:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-10 13:22 [pbs-devel] [PATCH v2 proxmox-backup 1/2] add extra_info field to APTUpdateInfo Mira Limbeck
2020-11-10 13:22 ` [pbs-devel] [PATCH v2 proxmox-backup 2/2] add versions command to proxmox-backup-manager Mira Limbeck
2020-11-11 17:38 ` [pbs-devel] applied: " Thomas Lamprecht
2020-11-12 9:12 ` Stefan Reiter [this message]
2020-11-12 9:18 ` [pbs-devel] applied: [PATCH proxmox-backup] apt: use typed response for get_versions Thomas Lamprecht
[not found] ` <c16a8594-0f66-eadb-1063-d6309187a4e5@proxmox.com>
2020-11-12 9:29 ` [pbs-devel] applied: [PATCH v2 proxmox-backup 2/2] add versions command to proxmox-backup-manager Thomas Lamprecht
2020-11-11 11:59 ` [pbs-devel] [PATCH v2 proxmox-backup 1/2] add extra_info field to APTUpdateInfo Mira Limbeck
2020-11-11 17:33 ` [pbs-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201112091254.29059-1-s.reiter@proxmox.com \
--to=s.reiter@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox