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

Added dev args to wrangler.toml #1477

Merged
merged 3 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 19 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,17 +751,31 @@ 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<u16> = 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 host: Option<&str> = matches.value_of("host");
let mut ip: Option<&str> = matches.value_of("ip");
let mut port: Option<u16> = 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 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;
Expand Down
8 changes: 8 additions & 0 deletions src/settings/toml/dev.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Dev {
pub ip: Option<String>,
pub port: Option<u16>,
}
2 changes: 2 additions & 0 deletions src/settings/toml/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Site>,
pub dev: Option<Dev>,
#[serde(alias = "kv-namespaces")]
pub kv_namespaces: Option<Vec<ConfigKvNamespace>>,
pub env: Option<HashMap<String, Environment>>,
Expand Down
1 change: 1 addition & 0 deletions src/settings/toml/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod deploy_config;
mod dev;
mod environment;
mod kv_namespace;
mod manifest;
Expand Down