Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BP] Lazily calculate value when using StyledTable::add_kv_row_if and predicate is true #1633

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Lazily calculate value when using StyledTable::add_kv_row_if and pred…
…icate is true

We use StyledTable::add_kv_row_if to check if a value exists. We should only access the
value if the predicate passes. That's why this command changes the value parameter into
a closure that is evaluated if the predicate is true.

This fixes #1631.
  • Loading branch information
tillrohrmann committed Jun 14, 2024
commit 6f1a4e2186701ef061a493332c6bce2e252d3584
2 changes: 1 addition & 1 deletion cli/src/commands/invocations/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn describe(env: &CliEnv, opts: &Describe) -> Result<()> {
table.add_kv_row_if(
|| inv.state_modified_at.is_some(),
"Modified at:",
format!("{}", &inv.state_modified_at.unwrap()),
|| format!("{}", &inv.state_modified_at.unwrap()),
);

c_title!("📜", "Invocation Information");
Expand Down
4 changes: 2 additions & 2 deletions cli/src/ui/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ pub trait StyledTable {
fn new_styled(ui_config: &UiConfig) -> Self;
fn set_styled_header<T: ToString>(&mut self, headers: Vec<T>) -> &mut Self;
fn add_kv_row<V: Into<comfy_table::Cell>>(&mut self, key: &str, value: V) -> &mut Self;
fn add_kv_row_if<P: Fn() -> bool, V: Display>(
fn add_kv_row_if<P: Fn() -> bool, V: Fn() -> D, D: Display>(
&mut self,
predicate: P,
key: &str,
value: V,
) -> &mut Self {
if predicate() {
self.add_kv_row(key, value)
self.add_kv_row(key, value())
} else {
self
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/ui/deployments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn add_deployment_to_kv_table(deployment: &Deployment, table: &mut Table) {
table.add_kv_row_if(
|| assume_role_arn.is_some(),
"Deployment Assume Role ARN:",
assume_role_arn.as_ref().unwrap(),
|| assume_role_arn.as_ref().unwrap(),
);

table.add_kv_row("Endpoint:", arn);
Expand Down
Loading