[pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format

Dominik Csapak d.csapak at proxmox.com
Fri Apr 30 14:51:55 CEST 2021


just getting it is not enough, sometimes we want it to remove from
params (if possble) too

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 proxmox/src/api/cli/text_table.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/proxmox/src/api/cli/text_table.rs b/proxmox/src/api/cli/text_table.rs
index 5ff2db0..84d9f34 100644
--- a/proxmox/src/api/cli/text_table.rs
+++ b/proxmox/src/api/cli/text_table.rs
@@ -25,6 +25,18 @@ pub fn get_output_format(param: &Value) -> String {
     output_format.unwrap_or_else(|| String::from("text"))
 }
 
+/// Helper to get output format from parameters or environment
+/// and removing from parameters
+pub fn extract_output_format(param: &mut Value) -> String {
+    let output_format = get_output_format(param);
+
+    if let Some(param) = param.as_object_mut() {
+        param.remove("output-format");
+    }
+
+    output_format
+}
+
 /// Helper to get TableFormatOptions with default from environment
 pub fn default_table_format_options() -> TableFormatOptions {
     let no_border = std::env::var(ENV_VAR_PROXMOX_OUTPUT_NO_BORDER)
-- 
2.20.1






More information about the pbs-devel mailing list