Skip to content

Commit

Permalink
Add back support for BROWSER envvar in cargo doc --open.
Browse files Browse the repository at this point in the history
Fixes #6064.
Fixes #5965.
  • Loading branch information
orium committed Nov 11, 2019
1 parent 0c0f9ae commit 23a2efe
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 44 deletions.
26 changes: 24 additions & 2 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::core::resolver::ResolveOpts;
use crate::core::Workspace;
use crate::core::{Shell, Workspace};
use crate::ops;
use crate::util::CargoResult;
use failure::Fail;
use opener;
use std::collections::HashMap;
use std::error::Error;
use std::path::Path;
use std::process::Command;

/// Strongly typed options for the `cargo doc` command.
#[derive(Debug)]
Expand Down Expand Up @@ -77,14 +80,33 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
if path.exists() {
let mut shell = options.compile_opts.config.shell();
shell.status("Opening", path.display())?;
open_docs(&path, &mut shell)?;
}
}

Ok(())
}

fn open_docs(path: &Path, shell: &mut Shell) -> CargoResult<()> {
match std::env::var_os("BROWSER") {
Some(browser) => {
if let Err(e) = Command::new(&browser).arg(path).status() {
shell.warn(format!(
"Couldn't open docs with {}: {}",
browser.to_string_lossy(),
e.description()
))?;
}
}
None => {
if let Err(e) = opener::open(&path) {
shell.warn(format!("Couldn't open docs: {}", e))?;
for cause in (&e as &dyn Fail).iter_chain() {
shell.warn(format!("Caused by:\n {}", cause))?;
}
}
}
}
};

Ok(())
}
4 changes: 3 additions & 1 deletion src/doc/man/cargo-doc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ is placed in `target/doc` in rustdoc's usual format.
=== Documentation Options

*--open*::
Open the docs in a browser after building them.
Open the docs in a browser after building them. This will use your default
browser unless you define another one in the `BROWSER` environment
variable.

*--no-deps*::
Do not build documentation for dependencies.
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/cargo-rustdoc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ option.
=== Documentation Options

*--open*::
Open the docs in a browser after building them.
Open the docs in a browser after building them. This will use your default
browser unless you define another one in the `BROWSER` environment
variable.

=== Package Selection

Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated/cargo-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ <h3 id="cargo_doc_documentation_options">Documentation Options</h3>
<dl>
<dt class="hdlist1"><strong>--open</strong></dt>
<dd>
<p>Open the docs in a browser after building them.</p>
<p>Open the docs in a browser after building them. This will use your default
browser unless you define another one in the <code>BROWSER</code> environment
variable.</p>
</dd>
<dt class="hdlist1"><strong>--no-deps</strong></dt>
<dd>
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated/cargo-rustdoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ <h3 id="cargo_rustdoc_documentation_options">Documentation Options</h3>
<dl>
<dt class="hdlist1"><strong>--open</strong></dt>
<dd>
<p>Open the docs in a browser after building them.</p>
<p>Open the docs in a browser after building them. This will use your default
browser unless you define another one in the <code>BROWSER</code> environment
variable.</p>
</dd>
</dl>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/etc/man/cargo-doc.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: cargo-doc
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05
.\" Date: 2019-11-11
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-DOC" "1" "2019-09-05" "\ \&" "\ \&"
.TH "CARGO\-DOC" "1" "2019-11-11" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -41,7 +41,9 @@ is placed in \fBtarget/doc\fP in rustdoc\(cqs usual format.
.sp
\fB\-\-open\fP
.RS 4
Open the docs in a browser after building them.
Open the docs in a browser after building them. This will use your default
browser unless you define another one in the \fBBROWSER\fP environment
variable.
.RE
.sp
\fB\-\-no\-deps\fP
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-help.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-help
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-HELP" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-HELP" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-init
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-INIT" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-INIT" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-install.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-install
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-07-15
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-10-09
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-INSTALL" "1" "2019-07-15" "\ \&" "\ \&"
.TH "CARGO\-INSTALL" "1" "2019-10-09" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-login.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-login
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-LOGIN" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-LOGIN" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-new.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-new
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-NEW" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-NEW" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-owner.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-owner
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-OWNER" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-OWNER" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
8 changes: 5 additions & 3 deletions src/etc/man/cargo-rustdoc.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: cargo-rustdoc
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05
.\" Date: 2019-11-11
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-RUSTDOC" "1" "2019-09-05" "\ \&" "\ \&"
.TH "CARGO\-RUSTDOC" "1" "2019-11-11" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -58,7 +58,9 @@ option.
.sp
\fB\-\-open\fP
.RS 4
Open the docs in a browser after building them.
Open the docs in a browser after building them. This will use your default
browser unless you define another one in the \fBBROWSER\fP environment
variable.
.RE
.SS "Package Selection"
.sp
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-search.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-search
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-SEARCH" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-SEARCH" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-uninstall.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-uninstall
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-UNINSTALL" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-UNINSTALL" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-version.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-version
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-VERSION" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-VERSION" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
6 changes: 3 additions & 3 deletions src/etc/man/cargo-yank.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-yank
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8
.\" Date: 2019-06-07
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-03
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO\-YANK" "1" "2019-06-07" "\ \&" "\ \&"
.TH "CARGO\-YANK" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down
4 changes: 2 additions & 2 deletions src/etc/man/cargo.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: cargo
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05
.\" Date: 2019-10-09
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "CARGO" "1" "2019-09-05" "\ \&" "\ \&"
.TH "CARGO" "1" "2019-10-09" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down

0 comments on commit 23a2efe

Please sign in to comment.