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

feat: prettier table #315

Merged
merged 1 commit into from
Mar 1, 2021
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
12 changes: 6 additions & 6 deletions installers/npm/package-lock.json

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

8 changes: 5 additions & 3 deletions src/command/graph/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use prettytable::{cell, row, Table};
use serde::Serialize;
use structopt::StructOpt;

Expand All @@ -12,6 +11,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::{self, cell, row};
use crate::Result;

#[derive(Debug, Serialize, StructOpt)]
Expand Down Expand Up @@ -111,8 +111,10 @@ 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();

// bc => sets top row to be bold and center
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added comments are perfect :) I imagine most of the time this will be copy/pasted anyway!

table.add_row(row![bc => "Change", "Code", "Description"]);
JakeDawkins marked this conversation as resolved.
Show resolved Hide resolved
for check in checks {
let change = match check.severity {
check::check_schema_query::ChangeSeverity::NOTICE => "PASS",
Expand Down
15 changes: 10 additions & 5 deletions src/command/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::collections::HashMap;
use std::fmt::Debug;

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

use crate::utils::table::{self, cell, row};

/// 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 All @@ -31,8 +32,10 @@ impl RoverStdout {
"You can open any of these documentation pages by running {}.\n",
Yellow.normal().paint("`rover docs open <slug>`")
);
let mut table = Table::new();
table.add_row(row!["Slug", "Description"]);
let mut table = table::get_table();

// bc => sets top row to be bold and center
table.add_row(row![bc => "Slug", "Description"]);
for (shortlink_slug, shortlink_description) in shortlinks {
table.add_row(row![shortlink_slug, shortlink_description]);
}
Expand All @@ -47,8 +50,10 @@ 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();

// bc => sets top row to be bold and center
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
8 changes: 5 additions & 3 deletions src/command/subgraph/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use prettytable::{cell, row, Table};
use serde::Serialize;
use structopt::StructOpt;

Expand All @@ -13,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::{self, cell, row};

#[derive(Debug, Serialize, StructOpt)]
pub struct Check {
Expand Down Expand Up @@ -119,8 +119,10 @@ 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();

// bc => sets top row to be bold and center
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;
9 changes: 9 additions & 0 deletions src/utils/table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use prettytable::{format::consts::FORMAT_BOX_CHARS, Table};

pub use prettytable::{cell, row};

pub fn get_table() -> Table {
let mut table = Table::new();
table.set_format(*FORMAT_BOX_CHARS);
table
}