Skip to content

Commit

Permalink
fix[serve]: config file option serve.open is ignored
Browse files Browse the repository at this point in the history
Fixes #847
  • Loading branch information
mnemotic committed Aug 27, 2024
1 parent 5f667ab commit fd21baa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@
"default": false,
"type": "boolean"
},
"open": {
"description": "Open a browser tab once the initial build is complete [default: false]",
"default": false,
"type": "boolean"
},
"port": {
"description": "The port to serve on [default: 8080]",
"default": 8080,
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub struct Serve {
pub port: Option<u16>,
/// Open a browser tab once the initial build is complete [default: false]
#[arg(long, env = "TRUNK_SERVE_OPEN")]
pub open: bool,
#[arg(default_missing_value="true", num_args=0..=1)]
pub open: Option<bool>,
/// Disable auto-reload of the web app
#[arg(long, env = "TRUNK_SERVE_NO_AUTORELOAD")]
#[arg(default_missing_value="true", num_args=0..=1)]
Expand Down Expand Up @@ -98,7 +99,7 @@ impl Serve {
address,
prefer_address_family,
port,
open: _,
open,
proxy:
ProxyArgs {
proxy_backend,
Expand All @@ -122,6 +123,7 @@ impl Serve {

config.serve.addresses = address.unwrap_or(config.serve.addresses);
config.serve.port = port.unwrap_or(config.serve.port);
config.serve.open = open.unwrap_or(config.serve.open);
config.serve.prefer_address_family =
prefer_address_family.or(config.serve.prefer_address_family);
config.serve.serve_base = serve_base.or(config.serve.serve_base);
Expand Down Expand Up @@ -173,7 +175,8 @@ impl Serve {
enable_cooldown: self.watch.enable_cooldown,
no_error_reporting: cfg.serve.no_error_reporting,
},
open: self.open,
// This will be the effective value for `serve.open` during runtime.
open: self.open.unwrap_or(cfg.serve.open),
})
.await?;

Expand Down
4 changes: 4 additions & 0 deletions src/config/models/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct Serve {
/// The port to serve on [default: 8080]
#[serde(default = "default::port")]
pub port: u16,
/// Open a browser tab once the initial build is complete [default: false]
#[serde(default)]
pub open: bool,
/// Disable auto-reload of the web app
#[serde(default)]
pub no_autoreload: bool,
Expand Down Expand Up @@ -80,6 +83,7 @@ impl Default for Serve {
addresses: vec![],
prefer_address_family: None,
port: default::port(),
open: false,
no_autoreload: false,
headers: Default::default(),
no_error_reporting: false,
Expand Down
1 change: 1 addition & 0 deletions src/config/rt/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl RtcServe {
addresses,
prefer_address_family,
port,
open: _,
// auto-reload is handle by the builder options
no_autoreload: _,
headers,
Expand Down

0 comments on commit fd21baa

Please sign in to comment.