Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

unifies attention grabbing messages #1128

Merged
merged 1 commit into from
Mar 6, 2020
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
58 changes: 58 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build = "build.rs"
atty = "0.2.11"
base64 = "0.10.1"
binary-install = "0.0.3-alpha"
boxx = "0.0.2-beta"
chrome-devtools-rs = { version = "0.0.0-alpha.0", features = ["color"] }
chrono = "0.4.9"
clap = "2.32.0"
Expand Down Expand Up @@ -50,8 +51,8 @@ serde_json = "1.0.39"
serde_with = "1.3.1"
sha2 = "0.8.0"
tempfile = "3.1.0"
text_io = "0.1.7"
term_size = "0.3"
text_io = "0.1.7"
tokio = { version = "0.2", default-features = false, features = ["io-std", "time"] }
tokio-tungstenite = { version = "0.10.1", features = ["tls"] }
toml = "0.5.5"
Expand Down
9 changes: 7 additions & 2 deletions src/commands/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
use std::thread;

use chrono::prelude::*;
use console::style;

use hyper::client::{HttpConnector, ResponseFuture};
use hyper::header::{HeaderName, HeaderValue};
Expand All @@ -30,7 +31,7 @@ use crate::commands::preview::upload;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;

use crate::terminal::{emoji, message_box};
use crate::terminal::{emoji, message};

const PREVIEW_HOST: &str = "rawhttp.cloudflareworkers.com";

Expand All @@ -42,7 +43,11 @@ pub fn dev(
ip: Option<&str>,
verbose: bool,
) -> Result<(), failure::Error> {
message_box::dev_alpha_warning();
let wrangler_dev_msg = style("`wrangler dev`").yellow().bold();
let feedback_url = style("https://github.com/cloudflare/wrangler/issues/1047")
.blue()
.bold();
message::billboard(&format!("{0} is currently unstable and there are likely to be breaking changes!\nFor this reason, we cannot yet recommend using {0} for integration testing.\n\nPlease submit any feedback here: {1}", wrangler_dev_msg, feedback_url));
commands::build(&target)?;
let server_config = ServerConfig::new(host, ip, port)?;
let session_id = get_session_id()?;
Expand Down
13 changes: 8 additions & 5 deletions src/commands/preview/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::upload;
use reqwest::blocking::Client;
use serde::Deserialize;

use console::style;

#[derive(Debug, Deserialize)]
struct Preview {
id: String,
Expand Down Expand Up @@ -75,13 +77,14 @@ pub fn upload(
}
}
None => {
message::warn(
"You haven't run `wrangler config`. Running preview without authentication",
);
message::big_info(
"Please run `wrangler config` or visit https://developers.cloudflare.com/workers/tooling/wrangler/configuration/#using-environment-variables for info on configuring with environment variables",
let wrangler_config_msg = style("`wrangler config`").yellow().bold();
let docs_url_msg = style("https://developers.cloudflare.com/workers/tooling/wrangler/configuration/#using-environment-variables").blue().bold();
message::billboard(
&format!("You have not provided your Cloudflare credentials.\n\nPlease run {} or visit\n{}\nfor info on authenticating with environment variables.", wrangler_config_msg, docs_url_msg)
);

message::info("Running preview without authentication.");

if sites_preview {
failure::bail!(SITES_UNAUTH_PREVIEW_ERR)
}
Expand Down
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::str::FromStr;

use clap::{App, AppSettings, Arg, ArgGroup, SubCommand};
use commands::HTTPMethod;
use console::style;
use exitfailure::ExitFailure;

use wrangler::commands;
Expand Down Expand Up @@ -508,20 +509,30 @@ fn run() -> Result<(), failure::Error> {

let config_path = Path::new("./wrangler.toml");

let not_recommended_msg = style("(Not Recommended)").red().bold();
let recommended_cmd_msg = style("`wrangler config --api-key`").yellow().bold();
let api_token_url = style("https://dash.cloudflare.com/profile/api-tokens")
.blue()
.bold();
let token_support_url = style(
"https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys",
)
.blue()
.bold();

if let Some(matches) = matches.subcommand_matches("config") {
// If api-key flag isn't present, use the default auth option (API token)
let default = !matches.is_present("api-key");

let user: GlobalUser = if default {
// API Tokens are the default
message::big_info("To find your API token, go to https://dash.cloudflare.com/profile/api-tokens\n\tand create it using the \"Edit Cloudflare Workers\" template");
message::big_info("If you are trying to use your Global API Key instead of an API Token\n\t(Not Recommended), run \"wrangler config --api-key\".\n");
let api_token: String = interactive::get_user_input("Enter API token: ");
message::billboard(&format!("To find your API Token, go to {}\nand create it using the \"Edit Cloudflare Workers\" template.\n\nIf you are trying to use your Global API Key instead of an API Token\n{}, run {}.", not_recommended_msg, recommended_cmd_msg, api_token_url));
Copy link
Member

Choose a reason for hiding this comment

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

The arguments seem to be out of order:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๐Ÿ‘€ good catch! thanks

let api_token: String = interactive::get_user_input("Enter API Token: ");
GlobalUser::TokenAuth { api_token }
} else {
message::big_info("We don't recommend using your Global API Key! Please consider using an\n\tAPI Token instead.\n\thttps://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys\n");
let email: String = interactive::get_user_input("Enter email: ");
let api_key: String = interactive::get_user_input("Enter global API key: ");
message::billboard(&format!("We don't recommend using your Global API Key!\nPlease consider using an API Token instead.\n\n{}", token_support_url));
let email: String = interactive::get_user_input("Enter Email: ");
let api_key: String = interactive::get_user_input("Enter Global API Key: ");

GlobalUser::GlobalKeyAuth { email, api_key }
};
Expand Down
17 changes: 11 additions & 6 deletions src/terminal/message.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#![allow(dead_code)]
use super::emoji;

use boxx::{BorderColor, BorderStyle, Boxx};

fn message(msg: &str) {
println!("{}", msg);
}

pub fn info(msg: &str) {
let msg = format!("{} {}", emoji::INFO, msg);
message(&msg);
pub fn billboard(msg: &str) {
let billboard = Boxx::builder()
.border_style(BorderStyle::Round)
.border_color(BorderColor::Cyan)
.margin(1)
.build();
billboard.display(msg);
}

pub fn big_info(msg: &str) {
let msg = format!("\n\t{} {}", emoji::INFO, msg);
pub fn info(msg: &str) {
let msg = format!("{} {}", emoji::INFO, msg);
message(&msg);
}

Expand Down
111 changes: 0 additions & 111 deletions src/terminal/message_box.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/terminal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod emoji;
pub mod interactive;
pub mod message;
pub mod message_box;