Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/_test_area
/site
.idea
62 changes: 61 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rayon = "1.4"
colorsys = "0.5.7"
alphanumeric-sort = "1.4.0"
include_dir = "0.7.2"
open = "3.0.3"

[dev-dependencies]
indoc = "1.0.2"
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ fn main() {
Ok(_) => Ok(()),
Err(e) => Err(e.to_string()),
}),
),
).arg(
Arg::with_name("open")
.long("open")
.short("o")
.help("Opens the docs site on chrome")
)
,
)
.get_matches();

Expand Down Expand Up @@ -118,6 +124,8 @@ fn serve(cmd: &ArgMatches) -> doctave::Result<()> {
options.port = Some(p.parse::<u32>().unwrap());
}

options.open = cmd.is_present("open");

if cmd.is_present("no-color") {
config.disable_colors();
}
Expand Down
12 changes: 11 additions & 1 deletion src/preview_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ pub struct PreviewServer<B: SiteBackend> {
base_path: String,
addr: SocketAddr,
site: Arc<Site<B>>,
open: bool
}

impl<B: SiteBackend> PreviewServer<B> {
pub fn new(addr: &str, site: Arc<Site<B>>, color: bool, base_path: String) -> Self {
pub fn new(addr: &str, site: Arc<Site<B>>, color: bool, base_path: String, open: bool) -> Self {
PreviewServer {
addr: addr.parse().expect("invalid address for preview server"),
site,
color,
base_path,
open
}
}

Expand All @@ -44,6 +46,10 @@ impl<B: SiteBackend> PreviewServer<B> {
self.base_path
)
.unwrap();

if self.open {
open_web_app(self.addr.to_string().as_str());
}
}

for request in server.incoming_requests() {
Expand Down Expand Up @@ -156,3 +162,7 @@ fn content_type_for(extension: Option<&OsStr>) -> Option<&'static str> {
None => None,
}
}

fn open_web_app(url: &str) -> std::io::Result<()> {
open::that("http://".to_owned()+url)
}
2 changes: 2 additions & 0 deletions src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct ServeCommand {}
#[derive(Default)]
pub struct ServeOptions {
pub port: Option<u32>,
pub open: bool
}

impl ServeCommand {
Expand Down Expand Up @@ -70,6 +71,7 @@ impl ServeCommand {
site.clone(),
config.color_enabled(),
config.base_path().to_owned(),
options.open
);
thread::Builder::new()
.name("http-server".into())
Expand Down