From 865b687ec9a1ba82c7b26ca6c9b1738222996e97 Mon Sep 17 00:00:00 2001 From: jspspike Date: Mon, 3 Aug 2020 14:58:58 -0500 Subject: [PATCH 1/2] Added dev args to wrangler.toml --- src/main.rs | 28 +++++++++++++++++++++++----- src/settings/toml/dev.rs | 9 +++++++++ src/settings/toml/manifest.rs | 2 ++ src/settings/toml/mod.rs | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/settings/toml/dev.rs diff --git a/src/main.rs b/src/main.rs index 709bce87e..3a5dcf038 100644 --- a/src/main.rs +++ b/src/main.rs @@ -751,17 +751,35 @@ fn run() -> Result<(), failure::Error> { commands::preview(target, user, options, verbose)?; } else if let Some(matches) = matches.subcommand_matches("dev") { log::info!("Starting dev server"); - let port: Option = matches - .value_of("port") - .map(|p| p.parse().expect("--port expects a number")); - let host = matches.value_of("host"); - let ip = matches.value_of("ip"); + let config_path = Path::new( matches .value_of("config") .unwrap_or(commands::DEFAULT_CONFIG_PATH), ); let manifest = settings::toml::Manifest::new(config_path)?; + + let mut host: Option<&str> = matches.value_of("host"); + let mut ip: Option<&str> = matches.value_of("ip"); + let mut port: Option = matches + .value_of("port") + .map(|p| p.parse().expect("--port expects a number")); + + // Check if arg not given but present in wrangler.toml + if let Some(d) = &manifest.dev { + if host.is_none() && d.host.is_some() { + host = d.host.as_deref(); + } + + if ip.is_none() && d.ip.is_some() { + ip = d.ip.as_deref(); + } + + if port.is_none() && d.port.is_some() { + port = d.port; + } + } + let env = matches.value_of("env"); let deploy_config = manifest.deploy_config(env)?; is_preview = true; diff --git a/src/settings/toml/dev.rs b/src/settings/toml/dev.rs new file mode 100644 index 000000000..649e857a9 --- /dev/null +++ b/src/settings/toml/dev.rs @@ -0,0 +1,9 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Dev { + pub host: Option, + pub ip: Option, + pub port: Option, +} diff --git a/src/settings/toml/manifest.rs b/src/settings/toml/manifest.rs index c2bf40e07..6a47424a0 100644 --- a/src/settings/toml/manifest.rs +++ b/src/settings/toml/manifest.rs @@ -11,6 +11,7 @@ use serde_with::rust::string_empty_as_none; use crate::commands::{validate_worker_name, DEFAULT_CONFIG_PATH}; use crate::settings::toml::deploy_config::{DeployConfig, RouteConfig}; +use crate::settings::toml::dev::Dev; use crate::settings::toml::environment::Environment; use crate::settings::toml::kv_namespace::{ConfigKvNamespace, KvNamespace}; use crate::settings::toml::site::Site; @@ -37,6 +38,7 @@ pub struct Manifest { // TODO: maybe one day, serde toml support will allow us to serialize sites // as a TOML inline table (this would prevent confusion with environments too!) pub site: Option, + pub dev: Option, #[serde(alias = "kv-namespaces")] pub kv_namespaces: Option>, pub env: Option>, diff --git a/src/settings/toml/mod.rs b/src/settings/toml/mod.rs index 8cc435879..72b945bbd 100644 --- a/src/settings/toml/mod.rs +++ b/src/settings/toml/mod.rs @@ -1,4 +1,5 @@ mod deploy_config; +mod dev; mod environment; mod kv_namespace; mod manifest; From a2b12b65e075bf36fdd0cb17bb2e936299cdc1b6 Mon Sep 17 00:00:00 2001 From: jspspike Date: Mon, 3 Aug 2020 15:34:55 -0500 Subject: [PATCH 2/2] Removed host from toml params --- src/main.rs | 6 +----- src/settings/toml/dev.rs | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a5dcf038..0415a23ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -759,7 +759,7 @@ fn run() -> Result<(), failure::Error> { ); let manifest = settings::toml::Manifest::new(config_path)?; - let mut host: Option<&str> = matches.value_of("host"); + let host: Option<&str> = matches.value_of("host"); let mut ip: Option<&str> = matches.value_of("ip"); let mut port: Option = matches .value_of("port") @@ -767,10 +767,6 @@ fn run() -> Result<(), failure::Error> { // Check if arg not given but present in wrangler.toml if let Some(d) = &manifest.dev { - if host.is_none() && d.host.is_some() { - host = d.host.as_deref(); - } - if ip.is_none() && d.ip.is_some() { ip = d.ip.as_deref(); } diff --git a/src/settings/toml/dev.rs b/src/settings/toml/dev.rs index 649e857a9..d3fd9cf69 100644 --- a/src/settings/toml/dev.rs +++ b/src/settings/toml/dev.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Dev { - pub host: Option, pub ip: Option, pub port: Option, }