Skip to content

Commit 3b26eae

Browse files
authored
Merge pull request #47 from EstebanBorai/feature/open-in-browser
Feature | Open in default browser
2 parents 47be257 + 1d5fbc7 commit 3b26eae

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pretty-bytes = "0.2.2"
2121
url = "2.1.0"
2222
hyper-native-tls = "0.3.0"
2323
mime_guess = "2.0"
24+
open = "1"
2425
# Iron crates
2526
iron = "0.6.1"
2627
iron-cors = "0.8.0"

src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use iron_cors::CorsMiddleware;
2323
use lazy_static::lazy_static;
2424
use mime_guess as mime_types;
2525
use multipart::server::{Multipart, SaveResult};
26+
use open;
2627
use path_dedot::ParseDot;
2728
use percent_encoding::percent_decode;
2829
use pretty_bytes::converter::convert;
@@ -197,6 +198,10 @@ fn main() {
197198
.short("s")
198199
.takes_value(false)
199200
.help("Disable all outputs"))
201+
.arg(clap::Arg::with_name("open")
202+
.long("open")
203+
.short("o")
204+
.help("Open the page in the default browser"))
200205
.get_matches();
201206

202207
let root = matches
@@ -242,6 +247,18 @@ fn main() {
242247
} else {
243248
format!("{:?}", compression_exts)
244249
};
250+
251+
let open = matches.is_present("open");
252+
253+
if open {
254+
let host = format!("http://{}", &addr);
255+
256+
match open::that(&host) {
257+
Ok(_) => println!("Openning {} in default browser", &host),
258+
Err(err) => eprintln!("Unable to open in default browser {}", err.to_string()),
259+
}
260+
}
261+
245262
let silent = matches.is_present("silent");
246263

247264
if !silent {

0 commit comments

Comments
 (0)