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

Add error codes #457

Merged
merged 30 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eadeff5
add some meaningless codes real quik
JakeDawkins Apr 15, 2021
1999bdc
rough explain command and md generation
JakeDawkins Apr 16, 2021
02a1db3
Update src/command/explain.rs
JakeDawkins Apr 21, 2021
001816c
add markdown formatting to code explanations
JakeDawkins Apr 26, 2021
1027b21
use strum to convert from str -> enum
JakeDawkins Apr 26, 2021
95b0a7c
lint
JakeDawkins Apr 26, 2021
0bddcbe
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins Apr 26, 2021
6bf602d
allow uppercase acronyms for EALL
JakeDawkins Apr 26, 2021
9f3df62
remove code for adhoc error
JakeDawkins Apr 26, 2021
f42b2d9
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins Apr 29, 2021
005f60e
remove md link replacing
JakeDawkins May 3, 2021
c3eec10
update string allocation
JakeDawkins May 3, 2021
d1c7f61
Merge branch 'jake/error-codes-coding-errors-code' of github.com:apol…
JakeDawkins May 3, 2021
2271d2e
first batch of error descriptions
JakeDawkins May 3, 2021
460e54a
update messages
JakeDawkins May 4, 2021
a1f8860
update error code descriptions
JakeDawkins May 4, 2021
45cd14b
build error reference in build.rs
JakeDawkins May 5, 2021
88aaa32
remove EALL
JakeDawkins May 5, 2021
2438982
lint
JakeDawkins May 5, 2021
65241bb
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins May 5, 2021
eb97d02
update changelog
JakeDawkins May 5, 2021
b9e9f1a
remove unused error code
JakeDawkins May 6, 2021
e544da1
update error message
JakeDawkins May 6, 2021
d36fc59
update code numbers
JakeDawkins May 6, 2021
4c2694c
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins May 6, 2021
2c7e8d6
add error code for composition failure
JakeDawkins May 6, 2021
8cbfe0a
update error docs
JakeDawkins May 6, 2021
662d1fb
Merge branch 'main' into jake/error-codes-coding-errors-code
lrlna May 10, 2021
62296a7
add E028
lrlna May 10, 2021
c93f47c
Create E028.md
lrlna May 10, 2021
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
139 changes: 139 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ structopt = "0.3.21"
toml = "0.5"
tracing = "0.1.22"
url = "2.2.0"
termimad = "0.10.1"
crossterm = "0.19.0"
strum = "0.20.0"
strum_macros = "0.20.1"

[dev-dependencies]
assert_cmd = "1.0.1"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub enum Command {
/// Get system information
#[structopt(setting(structopt::clap::AppSettings::Hidden))]
Info(command::Info),

/// Explain error codes
Explain(command::Explain),
}

impl Rover {
Expand Down Expand Up @@ -140,6 +143,7 @@ impl Rover {
Command::Update(command) => command.run(self.get_rover_config()?),
Command::Install(command) => command.run(self.get_install_override_path()?),
Command::Info(command) => command.run(),
Command::Explain(command) => command.run(),
}
}
}
25 changes: 25 additions & 0 deletions src/command/explain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::command::RoverStdout;
use crate::error::metadata::code::Code;
use crate::Result;
use serde::Serialize;
use structopt::StructOpt;

#[derive(Debug, Serialize, StructOpt)]
pub struct Explain {
/// The full error code. For example, E020
#[structopt(name = "CODE")]
code: Code,
}

impl Explain {
pub fn run(&self) -> Result<RoverStdout> {
let explanation = &self.code.explain();

// if we're printing all codes, we don't need to pretty print them
if self.code == Code::EALL {
Ok(RoverStdout::PlainText(explanation.clone()))
JakeDawkins marked this conversation as resolved.
Show resolved Hide resolved
} else {
Ok(RoverStdout::Markdown(explanation.clone()))
}
}
}
2 changes: 2 additions & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod config;
mod docs;
mod explain;
mod graph;
mod info;
mod install;
Expand All @@ -10,6 +11,7 @@ mod update;

pub use config::Config;
pub use docs::Docs;
pub use explain::Explain;
pub use graph::Graph;
pub use info::Info;
pub use install::Install;
Expand Down
31 changes: 28 additions & 3 deletions src/command/output.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::fmt::Debug;
use std::{collections::HashMap, fmt::Display};

use ansi_term::Colour::Yellow;
use crate::utils::table::{self, cell, row};
use ansi_term::Colour::{Cyan, Yellow};
use atty::Stream;
use crossterm::style::Attribute::*;
JakeDawkins marked this conversation as resolved.
Show resolved Hide resolved
use regex::Regex;
use rover_client::query::subgraph::list::ListDetails;

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

/// 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>`
Expand All @@ -25,6 +27,8 @@ pub enum RoverStdout {
VariantList(Vec<String>),
Profiles(Vec<String>),
Introspection(String),
Markdown(String),
PlainText(String),
None,
}

Expand Down Expand Up @@ -107,6 +111,27 @@ impl RoverStdout {
print_descriptor("Introspection Response");
println!("{}", &introspection_response);
}
RoverStdout::Markdown(markdown_string) => {
// underline bolded md
let mut skin = MadSkin::default();
skin.bold.add_attr(Underlined);

// replace links in format `[this](url)` to `this (url)`, since
// termimad doesn't handle links for us.

// this pattern captures the named groups, <title> and <url_with_parens>
// that we can use to replace with later
let re = Regex::new(r"\[(?P<title>[^\[]+)\](?P<url_with_parens>\(.*\))").unwrap();
JakeDawkins marked this conversation as resolved.
Show resolved Hide resolved
// we want to paint the replaced url cyan
// the $pattern labels in the replacer match the <pattern>s in the regex above
let replacer = format!("$title {}", Cyan.normal().paint("$url_with_parens"));
let reformatted_urls = re.replace_all(markdown_string, replacer);

println!("{}", skin.inline(&reformatted_urls));
}
RoverStdout::PlainText(text) => {
println!("{}", text);
}
RoverStdout::None => (),
}
}
Expand Down
Loading