Skip to content

Commit cd34433

Browse files
committed
Added --open to trunk serve to control opening of browser tab.
closes #22
1 parent 4209778 commit cd34433

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ changelog
22
=========
33

44
## Unreleased
5+
### changed
6+
- `trunk serve` now takes the `--open` option to control whether or not a browser tab will be opened. Thanks @MartinKavik for the report.
7+
- The `trunk serve` listener info has been slightly updated. It continues to function as in previous releases. Thanks @MartinKavik for the report.
58

69
## 0.1.3
710
### fixed
811
- Closed [#15](https://github.com/thedodd/trunk/issues/15): ensure cargo package name is processed as cargo itself processes package names (`s/-/_/`).
912
- Closed [#16](https://github.com/thedodd/trunk/issues/16): default to `index.html` as the default target for all CLI commands which expect a target. This matches the expectation of Seed & Yew.
1013

14+
Thanks @MartinKavik for reporting these items.
15+
1116
## 0.1.2
1217
### changed
1318
- Swap our `grass` for `sass-rs`.

src/cmd/serve.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub struct Serve {
3434
/// Additional paths to ignore.
3535
#[structopt(short, long, parse(from_os_str))]
3636
ignore: Option<Vec<PathBuf>>,
37+
/// Open a browser tab once the initial build is complete.
38+
#[structopt(long)]
39+
open: bool,
3740
}
3841

3942
impl Serve {
@@ -49,8 +52,10 @@ impl Serve {
4952
let server_handle = self.spawn_server()?;
5053

5154
// Open the browser.
52-
if let Err(err) = open::that(format!("http://localhost:{}", self.port)) {
53-
eprintln!("error opening browser: {}", err);
55+
if self.open {
56+
if let Err(err) = open::that(format!("http://127.0.0.1:{}", self.port)) {
57+
eprintln!("error opening browser: {}", err);
58+
}
5459
}
5560

5661
server_handle.await;
@@ -69,7 +74,7 @@ impl Serve {
6974
app.at(&self.public_url).serve_dir(self.dist.to_string_lossy().as_ref())?;
7075

7176
// Listen and serve.
72-
println!("📡 {}", format!("listening at http://{}", &listen_addr));
77+
println!("📡 {}", format!("listening on port {}", &self.port));
7378
Ok(spawn(async move {
7479
if let Err(err) = app.listen(listen_addr).await {
7580
eprintln!("{}", err);

0 commit comments

Comments
 (0)