From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id E1FBD1FF16E for ; Mon, 20 Jan 2025 10:30:40 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2892616230; Mon, 20 Jan 2025 10:30:40 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Mon, 20 Jan 2025 10:29:53 +0100 Message-Id: <20250120093006.927014-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250120093006.927014-1-d.csapak@proxmox.com> References: <20250120093006.927014-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH yew-comp 3/7] utils: factor out task description into own function X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" we'll need this separated from the UPID parsing code, so we can also use info from e.g. a `PveUpid` that we don't have here (yet). Signed-off-by: Dominik Csapak --- src/utils.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 24de356..d500b6d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -227,20 +227,22 @@ pub fn init_task_descr_table_base() { register_task_description("srvreload", (tr!("Service"), tr!("Reload"))); } +/// Uses information from the given [`UPID`] to render the task description with [`format_task_description`] pub fn format_upid(upid: &str) -> String { match upid.parse::() { Err(_) => upid.to_string(), - Ok(upid) => { - if let Some(text) = - lookup_task_description(upid.worker_type.as_str(), upid.worker_id.as_deref()) - { - text - } else { - match (upid.worker_type.as_str(), upid.worker_id) { - (worker_type, Some(id)) => format!("{} {}", worker_type, id), - (worker_type, None) => worker_type.to_string(), - } - } + Ok(upid) => format_task_description(&upid.worker_type, upid.worker_id.as_deref()), + } +} + +/// Formats the given worker type and id to a Human readable task description +pub fn format_task_description(worker_type: &str, worker_id: Option<&str>) -> String { + if let Some(text) = lookup_task_description(worker_type, worker_id) { + text + } else { + match worker_id { + Some(id) => format!("{} {}", worker_type, id), + None => worker_type.to_string(), } } } -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel