From ef379a199547fd16f27a2eff1323f3942e5dce1a Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Sat, 25 Mar 2023 15:43:38 +0100 Subject: [PATCH 1/3] feat: polish resource table styling --- cargo-shuttle/src/lib.rs | 6 ++-- common/src/models/resource.rs | 67 ++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 2a72e2525..4a4807c94 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -414,7 +414,7 @@ impl Shuttle { let resources = client .get_service_resources(self.ctx.project_name()) .await?; - let table = get_resources_table(&resources); + let table = get_resources_table(&resources, self.ctx.project_name().as_str()); println!("{table}"); @@ -583,7 +583,7 @@ impl Shuttle { .map(resource::Response::from_bytes) .collect(); - let resources = get_resources_table(&resources); + let resources = get_resources_table(&resources, self.ctx.project_name().as_str()); let mut stream = runtime_client .subscribe_logs(tonic::Request::new(SubscribeLogsRequest {})) @@ -695,7 +695,7 @@ impl Shuttle { let resources = client .get_service_resources(self.ctx.project_name()) .await?; - let resources = get_resources_table(&resources); + let resources = get_resources_table(&resources, self.ctx.project_name().as_str()); println!("{resources}{service}"); diff --git a/common/src/models/resource.rs b/common/src/models/resource.rs index 01a54f07b..497b7ffb0 100644 --- a/common/src/models/resource.rs +++ b/common/src/models/resource.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, path::PathBuf}; use comfy_table::{ - modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Cell, CellAlignment, ContentArrangement, - Table, + modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Attribute, Cell, CellAlignment, + ContentArrangement, Table, }; use crossterm::style::Stylize; @@ -11,7 +11,7 @@ use crate::{ DbOutput, SecretStore, }; -pub fn get_resources_table(resources: &Vec) -> String { +pub fn get_resources_table(resources: &Vec, service_name: &str) -> String { if resources.is_empty() { format!("{}\n", "No resources are linked to this service".bold()) } else { @@ -32,26 +32,26 @@ pub fn get_resources_table(resources: &Vec) -> String { let mut output = Vec::new(); if let Some(databases) = resource_groups.get("Databases") { - output.push(get_databases_table(databases)); + output.push(get_databases_table(databases, service_name)); }; if let Some(secrets) = resource_groups.get("Secrets") { - output.push(get_secrets_table(secrets)); + output.push(get_secrets_table(secrets, service_name)); }; if let Some(static_folders) = resource_groups.get("Static Folder") { - output.push(get_static_folder_table(static_folders)); + output.push(get_static_folder_table(static_folders, service_name)); }; if let Some(persist) = resource_groups.get("Persist") { - output.push(get_persist_table(persist)); + output.push(get_persist_table(persist, service_name)); }; output.join("\n") } } -fn get_databases_table(databases: &Vec<&Response>) -> String { +fn get_databases_table(databases: &Vec<&Response>, service_name: &str) -> String { let mut table = Table::new(); table @@ -59,8 +59,12 @@ fn get_databases_table(databases: &Vec<&Response>) -> String { .apply_modifier(UTF8_ROUND_CORNERS) .set_content_arrangement(ContentArrangement::DynamicFullWidth) .set_header(vec![ - Cell::new("Type").set_alignment(CellAlignment::Center), - Cell::new("Connection string").set_alignment(CellAlignment::Center), + Cell::new("Type") + .add_attribute(Attribute::Bold) + .set_alignment(CellAlignment::Center), + Cell::new("Connection string") + .add_attribute(Attribute::Bold) + .set_alignment(CellAlignment::Center), ]); for database in databases { @@ -74,19 +78,22 @@ fn get_databases_table(databases: &Vec<&Response>) -> String { } format!( - r#"These databases are linked to this service + r#"These databases are linked to {} {table} "#, + service_name.bold() ) } -fn get_secrets_table(secrets: &[&Response]) -> String { +fn get_secrets_table(secrets: &[&Response], service_name: &str) -> String { let mut table = Table::new(); table .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_header(vec![Cell::new("Key").set_alignment(CellAlignment::Center)]); + .set_header(vec![Cell::new("Keys") + .add_attribute(Attribute::Bold) + .set_alignment(CellAlignment::Center)]); let secrets = serde_json::from_value::(secrets[0].data.clone()).unwrap(); @@ -95,57 +102,61 @@ fn get_secrets_table(secrets: &[&Response]) -> String { } format!( - r#"These secrets can be accessed by the service + r#"These secrets can be accessed by {} {table} "#, + service_name.bold() ) } -fn get_static_folder_table(static_folders: &[&Response]) -> String { +fn get_static_folder_table(static_folders: &[&Response], service_name: &str) -> String { let mut table = Table::new(); table .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_content_arrangement(ContentArrangement::DynamicFullWidth) - .set_header(vec![ - Cell::new("Static Folders").set_alignment(CellAlignment::Center) - ]); + .set_header(vec![Cell::new("Static Folders") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold)]); for folder in static_folders { let path = serde_json::from_value::(folder.data.clone()) .unwrap() - .display() - .to_string(); + .file_name() + .expect("static folder path should have a final component") + .to_str() + .expect("static folder file name should be valid unicode") + .to_owned(); table.add_row(vec![path]); } format!( - r#"These static folders can be accessed by the service + r#"These static folders can be accessed by {} {table} "#, + service_name.bold() ) } -fn get_persist_table(persist_instances: &[&Response]) -> String { +fn get_persist_table(persist_instances: &[&Response], service_name: &str) -> String { let mut table = Table::new(); table .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_content_arrangement(ContentArrangement::DynamicFullWidth) - .set_header(vec![ - Cell::new("Persist Instances").set_alignment(CellAlignment::Center) - ]); + .set_header(vec![Cell::new("Persist Instances") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold)]); for _ in persist_instances { table.add_row(vec!["Instance"]); } format!( - r#"These instances are linked to this service + r#"These instances are linked to {} {table} "#, + service_name.bold() ) } From 0364512fac9f151b9a0dda0b9b980961f4882de3 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Sat, 25 Mar 2023 15:53:39 +0100 Subject: [PATCH 2/3] feat: make styling of other tables consistent --- common/src/models/deployment.rs | 16 +++++++++++----- common/src/models/secret.rs | 12 ++++++++---- common/src/models/service.rs | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index f3d5a2663..014f6483b 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use chrono::{DateTime, Utc}; use comfy_table::{ - modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Cell, CellAlignment, Color, + modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Attribute, Cell, CellAlignment, Color, ContentArrangement, Table, }; use crossterm::style::Stylize; @@ -59,9 +59,15 @@ pub fn get_deployments_table(deployments: &Vec, service_name: &str) -> .apply_modifier(UTF8_ROUND_CORNERS) .set_content_arrangement(ContentArrangement::DynamicFullWidth) .set_header(vec![ - Cell::new("ID").set_alignment(CellAlignment::Center), - Cell::new("Status").set_alignment(CellAlignment::Center), - Cell::new("Last updated").set_alignment(CellAlignment::Center), + Cell::new("Deployment ID") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), + Cell::new("Status") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), + Cell::new("Last updated") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), ]); for deploy in deployments.iter() { @@ -77,7 +83,7 @@ pub fn get_deployments_table(deployments: &Vec, service_name: &str) -> format!( r#" -Most recent deploys for {} +Most recent deployments for {} {} "#, service_name.bold(), diff --git a/common/src/models/secret.rs b/common/src/models/secret.rs index a89dfa1d0..e03664e33 100644 --- a/common/src/models/secret.rs +++ b/common/src/models/secret.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, Utc}; use comfy_table::{ - modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Cell, CellAlignment, ContentArrangement, - Table, + modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL, Attribute, Cell, CellAlignment, + ContentArrangement, Table, }; use crossterm::style::Stylize; use serde::{Deserialize, Serialize}; @@ -22,8 +22,12 @@ pub fn get_table(secrets: &Vec) -> String { .apply_modifier(UTF8_ROUND_CORNERS) .set_content_arrangement(ContentArrangement::DynamicFullWidth) .set_header(vec![ - Cell::new("Key").set_alignment(CellAlignment::Center), - Cell::new("Last updated").set_alignment(CellAlignment::Center), + Cell::new("Key") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), + Cell::new("Last updated") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), ]); for resource in secrets.iter() { diff --git a/common/src/models/service.rs b/common/src/models/service.rs index 8caae003a..4eff0ad6f 100644 --- a/common/src/models/service.rs +++ b/common/src/models/service.rs @@ -29,7 +29,7 @@ Status: {} Last Updated: {} URI: {} "#, - self.name, + self.name.clone().bold(), deployment.id, deployment .state From cee7d74a21f0818258e9a82157de1d2c34c6a753 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Sun, 26 Mar 2023 23:02:55 +0200 Subject: [PATCH 3/3] refactor: bold resource types --- common/src/models/deployment.rs | 5 +++-- common/src/models/resource.rs | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index 014f6483b..22c186c15 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -83,10 +83,11 @@ pub fn get_deployments_table(deployments: &Vec, service_name: &str) -> format!( r#" -Most recent deployments for {} +Most recent {} for {} {} "#, - service_name.bold(), + "deployments".bold(), + service_name, table, ) } diff --git a/common/src/models/resource.rs b/common/src/models/resource.rs index 497b7ffb0..de05e48d1 100644 --- a/common/src/models/resource.rs +++ b/common/src/models/resource.rs @@ -78,10 +78,11 @@ fn get_databases_table(databases: &Vec<&Response>, service_name: &str) -> String } format!( - r#"These databases are linked to {} + r#"These {} are linked to {} {table} "#, - service_name.bold() + "databases".bold(), + service_name ) } @@ -102,10 +103,11 @@ fn get_secrets_table(secrets: &[&Response], service_name: &str) -> String { } format!( - r#"These secrets can be accessed by {} + r#"These {} can be accessed by {} {table} "#, - service_name.bold() + "secrets".bold(), + service_name ) } @@ -115,7 +117,7 @@ fn get_static_folder_table(static_folders: &[&Response], service_name: &str) -> table .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_header(vec![Cell::new("Static Folders") + .set_header(vec![Cell::new("Folders") .set_alignment(CellAlignment::Center) .add_attribute(Attribute::Bold)]); @@ -132,10 +134,11 @@ fn get_static_folder_table(static_folders: &[&Response], service_name: &str) -> } format!( - r#"These static folders can be accessed by {} + r#"These {} can be accessed by {} {table} "#, - service_name.bold() + "static folders".bold(), + service_name ) } @@ -145,7 +148,7 @@ fn get_persist_table(persist_instances: &[&Response], service_name: &str) -> Str table .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_header(vec![Cell::new("Persist Instances") + .set_header(vec![Cell::new("Instances") .set_alignment(CellAlignment::Center) .add_attribute(Attribute::Bold)]); @@ -154,9 +157,10 @@ fn get_persist_table(persist_instances: &[&Response], service_name: &str) -> Str } format!( - r#"These instances are linked to {} + r#"These {} are linked to {} {table} "#, - service_name.bold() + "persist instances".bold(), + service_name ) }