Skip to content

Commit

Permalink
Replace prettytable-rs with comfy-table (#2413)
Browse files Browse the repository at this point in the history
Replace the prettytable-rs dependency with comfy-table. Resolves an
issue where the table output by `rover config whoami` was misalgined
due to an issue in prettytable-rs.
  • Loading branch information
pubmodmatt authored Feb 20, 2025
1 parent c31c00e commit 132ce31
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 108 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## 📚 Documentation -->

# [0.28.0] (unreleased) - 2025-mm-dd

## 🐛 Fixes

- **Fix formatting of table output by `rover config whoami` - @pubmodmatt PR #2413**

# [0.27.2] - 2025-02-19

## 🐛 Fixes
Expand Down
84 changes: 47 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ camino = { version = "1", features = ["serde1"] }
clap = "4"
chrono = "0.4"
ci_info = "0.14"
comfy-table = { version = "7.1.4", features = ["custom_styling"] }
console = "0.15"
derive-getters = "0.5.0"
dialoguer = "0.11"
Expand All @@ -118,7 +119,6 @@ os_info = "3.7"
os_type = "2.6"
predicates = "3"
pretty_assertions = "1"
prettytable-rs = "0.10"
regex = "1"
reqwest = { version = "0.12", default-features = false }
rstest = "0.23.0"
Expand Down Expand Up @@ -185,7 +185,6 @@ heck = { workspace = true }
http = { workspace = true }
houston = { workspace = true }
itertools = { workspace = true }
prettytable-rs = { workspace = true }
lazycell = { workspace = true }
lazy_static = { workspace = true }
opener = { workspace = true }
Expand Down Expand Up @@ -222,6 +221,7 @@ tower-lsp = { version = "0.20.0" }
tracing = { workspace = true }
uuid = { workspace = true }
url = { workspace = true, features = ["serde"] }
comfy-table = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rover-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ apollo-encoder = { workspace = true }
backoff = { workspace = true, features = ["tokio", "futures"] }
buildstructor = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
comfy-table = { workspace = true, features = ["custom_styling"]}
derive-getters = { workspace = true }
git-url-parse = { workspace = true }
git2 = { workspace = true, features = [
Expand All @@ -26,7 +27,6 @@ http = { workspace = true }
humantime = { workspace = true }
hyper = { workspace = true }
itertools = { workspace = true }
prettytable-rs = { workspace = true }
reqwest = { workspace = true, features = [
"blocking",
"brotli",
Expand Down
80 changes: 46 additions & 34 deletions crates/rover-client/src/shared/check_response.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fmt::{self, Display};
use std::str::FromStr;

use crate::{shared::lint_response::Diagnostic, RoverClientError};

use comfy_table::presets::UTF8_FULL;
use comfy_table::Attribute::Bold;
use comfy_table::CellAlignment::Center;
use comfy_table::{Cell, Table};
use rover_std::Style;
use std::fmt::{self, Display};
use std::str::FromStr;

use prettytable::format::consts::FORMAT_BOX_CHARS;
use serde::{Deserialize, Serialize};

use prettytable::{row, Table};
use serde_json::{json, Value};

#[derive(Debug, Serialize, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -174,13 +174,19 @@ impl OperationCheckResponse {

pub fn get_table(&self) -> String {
let mut table = Table::new();
table.load_preset(UTF8_FULL);

table.set_format(*FORMAT_BOX_CHARS);

// bc => sets top row to be bold and center
table.add_row(row![bc => "Change", "Code", "Description"]);
table.set_header(
vec!["Change", "Code", "Description"]
.into_iter()
.map(|s| Cell::new(s).set_alignment(Center).add_attribute(Bold)),
);
for check in &self.changes {
table.add_row(row![check.severity, check.code, check.description]);
table.add_row(vec![
&check.severity.to_string(),
&check.code,
&check.description,
]);
}

table.to_string()
Expand Down Expand Up @@ -224,18 +230,20 @@ pub struct LintCheckResponse {
impl LintCheckResponse {
pub fn get_table(&self) -> String {
let mut table = Table::new();
table.load_preset(UTF8_FULL);

table.set_format(*FORMAT_BOX_CHARS);

// bc => sets top row to be bold and center
table.add_row(row![bc => "Level", "Coordinate", "Line", "Description"]);
table.set_header(
vec!["Level", "Coordinate", "Line", "Description"]
.into_iter()
.map(|s| Cell::new(s).set_alignment(Center).add_attribute(Bold)),
);

for diagnostic in &self.diagnostics {
table.add_row(row![
diagnostic.level,
diagnostic.coordinate,
diagnostic.start_line,
diagnostic.message
table.add_row(vec![
&diagnostic.level,
&diagnostic.coordinate,
&diagnostic.start_line.to_string(),
&diagnostic.message,
]);
}

Expand Down Expand Up @@ -322,14 +330,16 @@ pub struct ProposalsCheckResponse {
impl ProposalsCheckResponse {
pub fn get_table(&self) -> String {
let mut table = Table::new();
table.load_preset(UTF8_FULL);

table.set_format(*FORMAT_BOX_CHARS);

// bc => sets top row to be bold and center
table.add_row(row![bc => "Status", "Proposal Name"]);
table.set_header(
vec!["Status", "Proposal Name"]
.into_iter()
.map(|s| Cell::new(s).set_alignment(Center).add_attribute(Bold)),
);

for proposal in &self.related_proposals {
table.add_row(row![proposal.status, proposal.display_name,]);
table.add_row(vec![&proposal.status, &proposal.display_name]);
}

table.to_string()
Expand Down Expand Up @@ -391,22 +401,24 @@ pub struct CustomCheckResponse {
impl CustomCheckResponse {
pub fn get_table(&self) -> String {
let mut table = Table::new();
table.load_preset(UTF8_FULL);

table.set_format(*FORMAT_BOX_CHARS);

// bc => sets top row to be bold and center
table.add_row(row![bc => "Level", "Rule", "Line", "Message"]);
table.set_header(
vec!["Level", "Rule", "Line", "Message"]
.into_iter()
.map(|s| Cell::new(s).set_alignment(Center).add_attribute(Bold)),
);

for violation in &self.violations {
let coordinate = match &violation.start_line {
Some(message) => message.to_string(),
None => "".to_string(),
};
table.add_row(row![
violation.level,
violation.rule,
coordinate,
violation.message,
table.add_row(vec![
&violation.level,
&violation.rule,
&coordinate,
&violation.message,
]);
}

Expand Down
Empty file removed src/command/check_workflow.rs
Empty file.
Loading

0 comments on commit 132ce31

Please sign in to comment.