Skip to content

Commit

Permalink
feat: prettier table
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Feb 26, 2021
1 parent 8e382dd commit f7331bb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/command/graph/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use prettytable::{cell, row, Table};
use prettytable::{cell, row};
use serde::Serialize;
use structopt::StructOpt;

Expand All @@ -12,6 +12,7 @@ use crate::utils::parsers::{
parse_graph_ref, parse_query_count_threshold, parse_query_percentage_threshold,
parse_schema_source, parse_validation_period, GraphRef, SchemaSource, ValidationPeriod,
};
use crate::utils::table;
use crate::Result;

#[derive(Debug, Serialize, StructOpt)]
Expand Down Expand Up @@ -111,8 +112,8 @@ fn print_changes(
let mut num_failures = 0;

if !checks.is_empty() {
let mut table = Table::new();
table.add_row(row!["Change", "Code", "Description"]);
let mut table = table::get_table();
table.add_row(row![bc => "Change", "Code", "Description"]);
for check in checks {
let change = match check.severity {
check::check_schema_query::ChangeSeverity::NOTICE => "PASS",
Expand Down
8 changes: 5 additions & 3 deletions src/command/output.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fmt::Debug;

use prettytable::{cell, row, Table};
use prettytable::{cell, row};
use rover_client::query::subgraph::list::ListDetails;

use crate::utils::table;

/// RoverStdout defines all of the different types of data that are printed
/// to `stdout`. Every one of Rover's commands should return `anyhow::Result<RoverStdout>`
/// If the command needs to output some type of data, it should be structured
Expand Down Expand Up @@ -32,8 +34,8 @@ impl RoverStdout {
println!("{}", &hash);
}
RoverStdout::SubgraphList(details) => {
let mut table = Table::new();
table.add_row(row!["Name", "Routing Url", "Last Updated"]);
let mut table = table::get_table();
table.add_row(row![bc => "Name", "Routing Url", "Last Updated"]);

for subgraph in &details.subgraphs {
// if the url is None or empty (""), then set it to "N/A"
Expand Down
7 changes: 4 additions & 3 deletions src/command/subgraph/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use prettytable::{cell, row, Table};
use prettytable::{cell, row};
use serde::Serialize;
use structopt::StructOpt;

Expand All @@ -13,6 +13,7 @@ use crate::utils::parsers::{
parse_graph_ref, parse_query_count_threshold, parse_query_percentage_threshold,
parse_schema_source, parse_validation_period, GraphRef, SchemaSource, ValidationPeriod,
};
use crate::utils::table;

#[derive(Debug, Serialize, StructOpt)]
pub struct Check {
Expand Down Expand Up @@ -119,8 +120,8 @@ fn handle_checks(check_result: check::CheckResult) -> Result<RoverStdout> {
let mut num_failures = 0;

if !check_result.changes.is_empty() {
let mut table = Table::new();
table.add_row(row!["Change", "Code", "Description"]);
let mut table = table::get_table();
table.add_row(row![bc => "Change", "Code", "Description"]);
for check in check_result.changes {
let change = match check.severity {
check::check_partial_schema_query::ChangeSeverity::NOTICE => "PASS",
Expand Down
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pub mod loaders;
pub mod parsers;
pub mod pkg;
pub mod stringify;
pub mod table;
pub mod telemetry;
25 changes: 25 additions & 0 deletions src/utils/table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use prettytable::{
format::{FormatBuilder, LinePosition, LineSeparator},
Table,
};

pub fn get_table() -> Table {
let mut table = Table::new();
table.set_format(
FormatBuilder::new()
.column_separator('│')
.borders('│')
.separators(&[LinePosition::Top], LineSeparator::new('─', '┬', '┌', '┐'))
.separators(
&[LinePosition::Intern],
LineSeparator::new('─', '┼', '├', '┤'),
)
.separators(
&[LinePosition::Bottom],
LineSeparator::new('─', '┴', '└', '┘'),
)
.padding(1, 1)
.build(),
);
table
}

0 comments on commit f7331bb

Please sign in to comment.