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

use new print macros in place of emojis #2096

Merged
merged 2 commits into from
Sep 3, 2024
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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Rover

>The new CLI for apollo

[![CircleCI Tests](https://circleci.com/gh/apollographql/rover.svg?style=svg)](https://app.circleci.com/pipelines/github/apollographql/rover?branch=main)
[![GitHub Release Downloads](https://shields.io/github/downloads/apollographql/rover/total.svg)](https://github.com/apollographql/rover/releases/latest)

Expand Down
10 changes: 5 additions & 5 deletions crates/rover-std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
time::Duration,
};

use crate::RoverStdError;
use crate::{errln, infoln, RoverStdError};
use anyhow::{anyhow, Context};
use camino::{ReadDirUtf8, Utf8Path, Utf8PathBuf};
use notify::event::ModifyKind;
Expand Down Expand Up @@ -258,7 +258,7 @@ impl Fs {
{
let path = path.as_ref().to_path_buf();
tokio::task::spawn_blocking(move || {
eprintln!("watching {} for changes", path.as_std_path().display());
infoln!("Watching {} for changes", path.as_std_path().display());
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for bringing this up now. I'm not sure my brain was fully functioning last week. I just sanity checked the guidelines we we've been using in rover here.
It seems like we might want to update infoln to print to stderr, as there's a guide there to use stderr for all messaging and stdout for output and this preserves the existing behavior (sans emojis)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. I see that now. I should try reading for a change.

let path = path.as_std_path();
let (fs_tx, fs_rx) = channel();
// Spawn a debouncer so we don't detect single rather than multiple writes in quick succession,
Expand Down Expand Up @@ -310,20 +310,20 @@ type WatchSender = UnboundedSender<Result<(), RoverStdError>>;
/// User-friendly error messages for `notify::Error` in `watch_file`
fn handle_notify_error(tx: &WatchSender, path: &Path, err: notify::Error) {
match &err.kind {
notify::ErrorKind::PathNotFound => eprintln!(
notify::ErrorKind::PathNotFound => errln!(
"could not watch \"{}\" for changes: file not found",
path.display()
),
notify::ErrorKind::MaxFilesWatch => {
eprintln!(
errln!(
"could not watch \"{}\" for changes: total number of inotify watches reached, consider increasing the number of allowed inotify watches or stopping processed that watch many files",
path.display()
);
}
notify::ErrorKind::Generic(_)
| notify::ErrorKind::Io(_)
| notify::ErrorKind::WatchNotFound
| notify::ErrorKind::InvalidConfig(_) => eprintln!(
| notify::ErrorKind::InvalidConfig(_) => errln!(
"an unexpected error occured while watching {} for changes",
path.display()
),
Expand Down
12 changes: 6 additions & 6 deletions crates/rover-std/src/print.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// Prints to the standard output, with a newline.
/// Prints to the standard error, with a newline.
///
/// Equivalent to the [`println!`] macro except that an info prefix is
/// Equivalent to the [`eprintln!`] macro except that an info prefix is
/// printed before the message.
#[macro_export]
macro_rules! infoln {
($($t:tt)*) => {{
print!("{} ", $crate::Style::InfoPrefix.paint("==>"));
println!($($t)*);
eprint!("{} ", $crate::Style::InfoPrefix.paint("==>"));
eprintln!($($t)*);
}};
}

Expand All @@ -17,7 +17,7 @@ macro_rules! infoln {
#[macro_export]
macro_rules! warnln {
($($t:tt)*) => {{
eprint!("{}: ", $crate::Style::WarningPrefix.paint("warning"));
eprint!("{} ", $crate::Style::WarningPrefix.paint("warning:"));
eprintln!($($t)*);
}};
}
Expand All @@ -29,7 +29,7 @@ macro_rules! warnln {
#[macro_export]
macro_rules! errln {
($($t:tt)*) => {{
eprint!("{}: ", $crate::Style::ErrorPrefix.paint("error"));
eprint!("{} ", $crate::Style::ErrorPrefix.paint("error:"));
eprintln!($($t)*);
}};
}
4 changes: 2 additions & 2 deletions src/command/dev/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::prelude::*;
use anyhow::{Context, Error};
use apollo_federation_types::config::{FederationVersion, SupergraphConfig};
use camino::Utf8PathBuf;
use rover_std::Fs;
use rover_std::{errln, Fs};

use crate::command::dev::do_dev::log_err_and_continue;
use crate::command::supergraph::compose::{Compose, CompositionOutput};
Expand Down Expand Up @@ -114,7 +114,7 @@ impl ComposeRunner {

fn remove_supergraph_schema(&self) -> RoverResult<()> {
if Fs::assert_path_exists(&self.write_path).is_ok() {
eprintln!("composition failed, killing the router");
errln!("composition failed, killing the router");
Ok(fs::remove_file(&self.write_path)
.with_context(|| format!("could not remove {}", &self.write_path))?)
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/command/dev/do_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures::channel::mpsc::channel;
use futures::future::join_all;
use futures::stream::StreamExt;
use futures::FutureExt;
use rover_std::warnln;

use crate::command::dev::protocol::FollowerMessage;
use crate::utils::client::StudioClientConfig;
Expand Down Expand Up @@ -57,8 +58,8 @@ impl Dev {
)
.await?
{
eprintln!(
"Do not run this command in production! It is intended for local development."
warnln!(
"Do not run this command in production! It is intended for local development only."
);
let (ready_sender, mut ready_receiver) = channel(1);
let follower_messenger = FollowerMessenger::from_main_session(
Expand Down
16 changes: 7 additions & 9 deletions src/command/dev/router/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use anyhow::{anyhow, Context};
use crossbeam_channel::Sender;
use rover_client::operations::config::who_am_i::{self, Actor, ConfigWhoAmIInput};
use rover_std::warnln;

use crate::options::ProfileOpt;
use crate::utils::client::StudioClientConfig;
Expand Down Expand Up @@ -54,27 +55,24 @@ impl BackgroundTask {
if let Ok(client) = client_config
.get_authenticated_client(profile_opt)
.map_err(|err| {
eprintln!(
"APOLLO_GRAPH_REF is set, but credentials could not be loaded. \
Enterprise features within the router will not function. {err}"
warnln!(
"APOLLO_GRAPH_REF is set, but credentials could not be loaded. Enterprise features within the router will not function: {err}"
);
})
{
if let Some(api_key) = who_am_i::run(ConfigWhoAmIInput {}, &client).await.map_or_else(|err| {
eprintln!("Could not determine the type of configured credentials, \
Router may fail to start if Enterprise features are enabled. {err}");
warnln!("Could not determine the type of configured credentials, Router may fail to start if Enterprise features are enabled: {err}");
Some(client.credential.api_key.clone())
}, |identity| {
match identity.key_actor_type {
Actor::GRAPH => Some(client.credential.api_key.clone()),
_ => {
eprintln!(
warnln!(
"APOLLO_GRAPH_REF is set, but the key provided is not a graph key. \
Enterprise features within the router will not function. \
Either select a `--profile` that is configured with a graph-specific \
key, or provide one via the APOLLO_KEY environment variable."
);
eprintln!("you can configure a graph key by following the instructions at https://www.apollographql.com/docs/graphos/api-keys/#graph-api-keys");
key, or provide one via the APOLLO_KEY environment variable. \
You can configure a graph key by following the instructions at https://www.apollographql.com/docs/graphos/api-keys/#graph-api-keys");
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/command/dev/router/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use camino::Utf8PathBuf;
use crossbeam_channel::{unbounded, Receiver};
use serde_json::json;

use rover_std::Fs;
use rover_std::{warnln, Fs};

use crate::utils::expansion::expand;
use crate::{
Expand Down Expand Up @@ -251,7 +251,7 @@ impl RouterConfigReader {

if let Some(path) = &self.input_config_path {
if Fs::assert_path_exists(path).is_err() {
eprintln!("{path} does not exist, creating a router config from CLI options.");
warnln!("{path} does not exist, creating a router config from CLI options.");
Fs::write_file(path, &yaml_string)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/command/dev/router/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use camino::Utf8PathBuf;
use crossbeam_channel::bounded;
use reqwest::Client;
use reqwest::Url;
use rover_std::Style;
use rover_std::{infoln, Style};
use semver::Version;

use std::net::SocketAddr;
Expand Down Expand Up @@ -129,7 +129,7 @@ impl RouterRunner {
}

if ready {
eprintln!(
infoln!(
"your supergraph is running! head to http://{}{} to query your supergraph",
&self
.router_socket_addr
Expand Down
6 changes: 3 additions & 3 deletions src/command/dev/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rover_client::blocking::StudioClient;
use rover_client::operations::subgraph::fetch;
use rover_client::operations::subgraph::fetch::SubgraphFetchInput;
use rover_client::shared::GraphRef;
use rover_std::Fs;
use rover_std::{errln, Fs};

use crate::{
command::dev::{
Expand Down Expand Up @@ -246,8 +246,8 @@ impl SubgraphSchemaWatcher {
//
if self.subgraph_retry_countdown > 0 {
self.subgraph_retry_countdown -= 1;
eprintln!("error detected communicating with subgraph '{}', schema changes will not be reflected.\nWill retry but subgraph logs should be inspected", &self.subgraph_key.0);
eprintln!("Error: {:}", e);
errln!("error detected communicating with subgraph '{}', schema changes will not be reflected.\nWill retry but subgraph logs should be inspected", &self.subgraph_key.0);
errln!("{:}", e);
Some(e.to_string())
} else {
eprintln!(
Expand Down
Loading