From 4cb6bd894c69705b235e063bcc7100effe8e9abc Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 23 Apr 2020 06:44:55 +0200 Subject: [PATCH] src/bin/proxmox-backup-manager.rs: improve network list output format --- src/bin/proxmox-backup-manager.rs | 35 ++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 4bce0b0b..6209f6b6 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -254,16 +254,41 @@ fn list_network_devices(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result _ => unreachable!(), }; + fn render_address(_value: &Value, record: &Value) -> Result { + let mut text = String::new(); + + if let Some(cidr) = record["cidr_v4"].as_str() { + text.push_str(cidr); + } + if let Some(cidr) = record["cidr_v6"].as_str() { + if !text.is_empty() { text.push('\n'); } + text.push_str(cidr); + } + + Ok(text) + } + + fn render_gateway(_value: &Value, record: &Value) -> Result { + let mut text = String::new(); + + if let Some(gateway) = record["gateway_v4"].as_str() { + text.push_str(gateway); + } + if let Some(gateway) = record["gateway_v6"].as_str() { + if !text.is_empty() { text.push('\n'); } + text.push_str(gateway); + } + + Ok(text) + } + let options = default_table_format_options() .column(ColumnConfig::new("name")) .column(ColumnConfig::new("auto")) .column(ColumnConfig::new("method_v4")) .column(ColumnConfig::new("method_v6")) - .column(ColumnConfig::new("cidr_v4")) - .column(ColumnConfig::new("gateway_v4")) - .column(ColumnConfig::new("cidr_v6")) - .column(ColumnConfig::new("gateway_v6")) - ; + .column(ColumnConfig::new("cidr_v4").header("address").renderer(render_address)) + .column(ColumnConfig::new("gateway_v4").header("gateway").renderer(render_gateway)); format_and_print_result_full(&mut data, info.returns, &output_format, &options);