Skip to content

Commit

Permalink
detect presence of terminal or NO_COLOR when configuring CLI error re…
Browse files Browse the repository at this point in the history
…porter (#564)
  • Loading branch information
erratic-pattern authored Oct 13, 2023
1 parent 3cf2b09 commit fa99793
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
80 changes: 37 additions & 43 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ termcolor = "1.1"
urlencoding = "2.1.0"
version-compare = "0.1.0"
webbrowser = "0.8.3"
is-terminal = "0.4.9"

[dev-dependencies]
cloudtruth-test-harness = { path = "./tests/harness" }
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use cloudtruth_config::env::ConfigEnv;
use cloudtruth_config::{Action, Config, Updates, CT_PROFILE, DEFAULT_ENV_NAME};
use cloudtruth_installer::{binary_version, get_latest_version, install_latest_version};
use color_eyre::eyre::Result;
use is_terminal::IsTerminal;
use std::io;
use std::process;
use utils::default;
Expand Down Expand Up @@ -137,7 +138,16 @@ fn check_updates(updates: &Updates) -> Result<()> {
}

pub fn main() -> Result<()> {
color_eyre::install()?;
/* color_eyre does not check NO_COLOR so we need to check */
if !std::io::stderr().is_terminal()
|| matches!(std::env::var("NO_COLOR"), Ok(no_color) if no_color != "0")
{
color_eyre::config::HookBuilder::new()
.theme(color_eyre::config::Theme::new())
.install()?;
} else {
color_eyre::install()?;
};
env_logger::init();

let profile_env = ConfigEnv::get_override(CT_PROFILE);
Expand Down

0 comments on commit fa99793

Please sign in to comment.