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

Commit

Permalink
Merge pull request #936 from cloudflare/avery/fix-clippy
Browse files Browse the repository at this point in the history
Addresses clippy warnings
  • Loading branch information
ashleymichal authored Dec 9, 2019
2 parents e37a63d + 57703f8 commit 79beb41
Show file tree
Hide file tree
Showing 46 changed files with 65 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod wranglerjs;
mod watch;
pub use watch::watch_and_build;

use crate::settings::target::{Target, TargetType};
use crate::settings::toml::{Target, TargetType};
use crate::terminal::message;
use crate::{commands, install};

Expand Down
4 changes: 2 additions & 2 deletions src/commands/build/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ignore::WalkBuilder;
pub use watcher::wait_for_changes;

use crate::commands::build::{command, wranglerjs};
use crate::settings::target::{Target, TargetType};
use crate::settings::toml::{Target, TargetType};
use crate::terminal::message;
use crate::{commands, install};

Expand All @@ -18,7 +18,7 @@ const JAVASCRIPT_PATH: &str = "./";
const RUST_PATH: &str = "./";

// Paths to ignore live watching in Rust Workers
const RUST_IGNORE: &'static [&str] = &["pkg", "target", "worker/generated"];
const RUST_IGNORE: &[&str] = &["pkg", "target", "worker/generated"];

// watch a project for changes and re-build it when necessary,
// outputting a build event to tx.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/build/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::commands::build::watch::wait_for_changes;
use crate::commands::build::watch::COOLDOWN_PERIOD;
use crate::commands::publish::package::Package;
use crate::install;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;
use crate::util;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;
use std::process::Command;

use crate::commands::validate_worker_name;
use crate::settings::target::{Manifest, Site, TargetType};
use crate::settings::toml::{Manifest, Site, TargetType};
use crate::{commands, install};

pub fn generate(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};

use crate::commands::validate_worker_name;
use crate::settings::target::{Manifest, Site, TargetType};
use crate::settings::toml::{Manifest, Site, TargetType};
use crate::terminal::message;

pub fn init(
Expand Down
15 changes: 6 additions & 9 deletions src/commands/kv/bucket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;
use ignore::overrides::{Override, OverrideBuilder};
use ignore::{Walk, WalkBuilder};

use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub const KEY_MAX_SIZE: usize = 512;
Expand Down Expand Up @@ -133,14 +133,11 @@ const NODE_MODULES: &str = "node_modules";

fn get_dir_iterator(target: &Target, directory: &Path) -> Result<Walk, failure::Error> {
// The directory provided should never be node_modules!
match directory.file_name() {
Some(name) => {
if name == NODE_MODULES {
failure::bail!("Your directory of files to upload cannot be named node_modules.");
}
if let Some(name) = directory.file_name() {
if name == NODE_MODULES {
failure::bail!("Your directory of files to upload cannot be named node_modules.");
}
_ => (),
}
};

let ignore = build_ignore(target, directory)?;
Ok(WalkBuilder::new(directory).overrides(ignore).build())
Expand Down Expand Up @@ -260,7 +257,7 @@ mod tests {
use std::fs;
use std::path::{Path, PathBuf};

use crate::settings::target::{Site, Target, TargetType};
use crate::settings::toml::{Site, Target, TargetType};

fn make_target(site: Site) -> Target {
Target {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/bucket/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::commands::kv::bucket::upload::upload_files;
use crate::commands::kv::bulk::delete::delete_bulk;
use crate::commands::kv::key::KeyList;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn sync(
Expand Down
6 changes: 2 additions & 4 deletions src/commands/kv/bucket/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::Path;
use crate::commands::kv;
use crate::commands::kv::bucket::directory_keys_values;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;
use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;
use cloudflare::framework::apiclient::ApiClient;
Expand Down Expand Up @@ -167,15 +167,13 @@ mod tests {

fn check_kv_pairs_equality(expected: Vec<KeyValuePair>, actual: Vec<KeyValuePair>) {
assert!(expected.len() == actual.len());
let mut idx = 0;
for pair in expected {
for (idx, pair) in expected.into_iter().enumerate() {
// Ensure the expected key and value was returned in the filtered pair list
// Awkward field-by-field comparison below courtesy of not yet implementing
// PartialEq for KeyValuePair in cloudflare-rs :)
// TODO: (gabbi) Implement PartialEq for KeyValuePair in cloudflare-rs.
assert!(pair.key == actual[idx].key);
assert!(pair.value == actual[idx].value);
idx += 1;
}
}
}
2 changes: 1 addition & 1 deletion src/commands/kv/bulk/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cloudflare::framework::apiclient::ApiClient;
use crate::commands::kv;
use crate::commands::kv::bulk::MAX_PAIRS;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn delete(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/bulk/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cloudflare::framework::response::{ApiFailure, ApiSuccess};
use crate::commands::kv;
use crate::commands::kv::bulk::MAX_PAIRS;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn put(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/key/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cloudflare::framework::apiclient::ApiClient;

use crate::commands::kv;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn delete(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/key/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cloudflare::framework::response::ApiFailure;
use crate::commands::kv;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;

pub fn get(target: &Target, user: &GlobalUser, id: &str, key: &str) -> Result<(), failure::Error> {
kv::validate_target(target)?;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/key/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::settings::global_user::GlobalUser;

use serde_json::value::Value as JsonValue;

use crate::settings::target::Target;
use crate::settings::toml::Target;

pub struct KeyList {
keys_result: Option<Vec<Key>>,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/key/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate serde_json;
use crate::commands::kv;
use crate::commands::kv::key::KeyList;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;

// Note: this function only prints keys in json form, given that
// the number of entries in each json blob is variable (so csv and tsv
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/key/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use url::Url;
use crate::commands::kv;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub struct KVMetaData {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cloudflare::framework::{HttpApiClient, HttpApiClientConfig};
use percent_encoding::{percent_encode, PATH_SEGMENT_ENCODE_SET};

use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;

use crate::http;

Expand Down Expand Up @@ -143,7 +143,7 @@ fn url_encode_key(key: &str) -> String {
#[cfg(test)]
mod tests {
use crate::commands::kv;
use crate::settings::target::{KvNamespace, Target, TargetType};
use crate::settings::toml::{KvNamespace, Target, TargetType};

#[test]
fn it_can_detect_duplicate_bindings() {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/namespace/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cloudflare::framework::response::{ApiFailure, ApiSuccess};

use crate::commands::kv;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;
use regex::Regex;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/namespace/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cloudflare::framework::apiclient::ApiClient;

use crate::commands::kv;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn delete(target: &Target, user: &GlobalUser, id: &str) -> Result<(), failure::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/namespace/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cloudflare::framework::response::{ApiFailure, ApiSuccess};

use crate::commands::kv;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;

const MAX_NAMESPACES_PER_PAGE: u32 = 100;
const PAGE_NUMBER: u32 = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/namespace/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cloudflare::framework::response::ApiFailure;

use crate::commands::kv;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

pub fn site(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/preview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use log::info;

use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;

use std::sync::mpsc::channel;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/preview/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::commands::kv::bucket::AssetManifest;
use crate::commands::publish;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::message;
use reqwest::Client;
use serde::Deserialize;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::commands::subdomain::Subdomain;
use crate::commands::validate_worker_name;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::{KvNamespace, Site, Target};
use crate::settings::toml::{KvNamespace, Site, Target};
use crate::terminal::{emoji, message};

pub fn publish(
Expand All @@ -37,7 +37,7 @@ pub fn publish(

if let Some(site_config) = target.site.clone() {
if let Some(route) = &target.route {
if !route.ends_with("*") {
if !route.ends_with('*') {
message::warn(&format!("The route in your wrangler.toml should have a trailing * to apply the Worker on every path, otherwise your site will not behave as expected.\nroute = {}*", route));
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/commands/publish/route.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::emoji;
use reqwest::header::CONTENT_TYPE;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -98,21 +98,20 @@ fn create(user: &GlobalUser, target: &Target, route: &Route) -> Result<(), failu
.send()?;

if !res.status().is_success() {
let msg;
if res.status().as_u16() == 10020 {
msg = format!(
let msg = if res.status().as_u16() == 10020 {
format!(
"{} A worker with a different name was previously deployed to `{}`. If you would like to overwrite that worker, you will need to change `name` in your `wrangler.toml` to match the currently deployed worker, or navigate to https://dash.cloudflare.com/workers and rename or delete that worker.\n",
emoji::WARN,
serde_json::to_string(&route)?
);
)
} else {
msg = format!(
format!(
"{} There was an error creating your route.\n Status Code: {}\n Msg: {}",
emoji::WARN,
res.status(),
res.text()?
);
}
)
};

failure::bail!(msg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/publish/upload_form/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::commands::build::wranglerjs;
use crate::commands::kv::bucket::AssetManifest;
use crate::settings::binding;
use crate::settings::metadata::Metadata;
use crate::settings::target::{Target, TargetType};
use crate::settings::toml::{Target, TargetType};

use project_assets::ProjectAssets;
use text_blob::TextBlob;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/publish/upload_form/project_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::filename_from_path;
use super::text_blob::TextBlob;
use super::wasm_module::WasmModule;

use crate::settings::target::KvNamespace;
use crate::settings::toml::KvNamespace;

#[derive(Debug)]
pub struct ProjectAssets {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/subdomain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::target::Target;
use crate::settings::toml::Target;
use crate::terminal::{emoji, message};

use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn auth_client(feature: Option<&str>, user: &GlobalUser) -> Client {
add_auth_headers(&mut headers, user);

builder()
.default_headers(headers.to_owned())
.default_headers(headers)
.redirect(RedirectPolicy::none())
.build()
.expect("could not create authenticated http client")
Expand Down
Loading

0 comments on commit 79beb41

Please sign in to comment.