From 91a73830fd0c9bf680ac6fc73482f83ae25d4e43 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Tue, 13 Feb 2024 22:09:28 +0330 Subject: [PATCH 1/2] fix logic error in indexing --- lib/cli/src/commands/app/logs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/src/commands/app/logs.rs b/lib/cli/src/commands/app/logs.rs index 2e64c75a517..b4f134325d3 100644 --- a/lib/cli/src/commands/app/logs.rs +++ b/lib/cli/src/commands/app/logs.rs @@ -113,7 +113,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs { while let Some(logs) = logs_stream.next().await { let logs = logs?; - let limit = std::cmp::max(logs.len(), rem); + let limit = std::cmp::min(logs.len(), rem); let logs = &logs[..limit]; if !logs.is_empty() { From 83d39dedbd7a5722709829a2d009a5cc9b2c7ca4 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Mon, 19 Feb 2024 07:55:00 +0330 Subject: [PATCH 2/2] use drain instead of slice index --- lib/cli/src/commands/app/logs.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cli/src/commands/app/logs.rs b/lib/cli/src/commands/app/logs.rs index b4f134325d3..aa15c686eaf 100644 --- a/lib/cli/src/commands/app/logs.rs +++ b/lib/cli/src/commands/app/logs.rs @@ -111,19 +111,20 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs { let mut rem = self.max; while let Some(logs) = logs_stream.next().await { - let logs = logs?; + let mut logs = logs?; let limit = std::cmp::min(logs.len(), rem); - let logs = &logs[..limit]; + let logs: Vec<_> = logs.drain(..limit).collect(); + if !logs.is_empty() { - let rendered = self.fmt.format.render(logs); + let rendered = self.fmt.format.render(&logs); println!("{rendered}"); rem -= limit; } - if !self.watch && rem == 0 { + if !self.watch || rem == 0 { break; } }