Skip to content

Commit f612284

Browse files
committed
Auto merge of #7576 - orium:add-back-support-for-browser-envvar, r=alexcrichton
Add back support for `BROWSER` envvar in `cargo doc --open`. Fixes #6064. Fixes #5965.
2 parents dd34668 + 23a2efe commit f612284

18 files changed

+78
-44
lines changed

src/cargo/ops/cargo_doc.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use crate::core::resolver::ResolveOpts;
2-
use crate::core::Workspace;
2+
use crate::core::{Shell, Workspace};
33
use crate::ops;
44
use crate::util::CargoResult;
55
use failure::Fail;
66
use opener;
77
use std::collections::HashMap;
8+
use std::error::Error;
9+
use std::path::Path;
10+
use std::process::Command;
811

912
/// Strongly typed options for the `cargo doc` command.
1013
#[derive(Debug)]
@@ -77,14 +80,33 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
7780
if path.exists() {
7881
let mut shell = options.compile_opts.config.shell();
7982
shell.status("Opening", path.display())?;
83+
open_docs(&path, &mut shell)?;
84+
}
85+
}
86+
87+
Ok(())
88+
}
89+
90+
fn open_docs(path: &Path, shell: &mut Shell) -> CargoResult<()> {
91+
match std::env::var_os("BROWSER") {
92+
Some(browser) => {
93+
if let Err(e) = Command::new(&browser).arg(path).status() {
94+
shell.warn(format!(
95+
"Couldn't open docs with {}: {}",
96+
browser.to_string_lossy(),
97+
e.description()
98+
))?;
99+
}
100+
}
101+
None => {
80102
if let Err(e) = opener::open(&path) {
81103
shell.warn(format!("Couldn't open docs: {}", e))?;
82104
for cause in (&e as &dyn Fail).iter_chain() {
83105
shell.warn(format!("Caused by:\n {}", cause))?;
84106
}
85107
}
86108
}
87-
}
109+
};
88110

89111
Ok(())
90112
}

src/doc/man/cargo-doc.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ is placed in `target/doc` in rustdoc's usual format.
2121
=== Documentation Options
2222

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

2628
*--no-deps*::
2729
Do not build documentation for dependencies.

src/doc/man/cargo-rustdoc.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ option.
3333
=== Documentation Options
3434

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

3840
=== Package Selection
3941

src/doc/man/generated/cargo-doc.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ <h3 id="cargo_doc_documentation_options">Documentation Options</h3>
2828
<dl>
2929
<dt class="hdlist1"><strong>--open</strong></dt>
3030
<dd>
31-
<p>Open the docs in a browser after building them.</p>
31+
<p>Open the docs in a browser after building them. This will use your default
32+
browser unless you define another one in the <code>BROWSER</code> environment
33+
variable.</p>
3234
</dd>
3335
<dt class="hdlist1"><strong>--no-deps</strong></dt>
3436
<dd>

src/doc/man/generated/cargo-rustdoc.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ <h3 id="cargo_rustdoc_documentation_options">Documentation Options</h3>
4545
<dl>
4646
<dt class="hdlist1"><strong>--open</strong></dt>
4747
<dd>
48-
<p>Open the docs in a browser after building them.</p>
48+
<p>Open the docs in a browser after building them. This will use your default
49+
browser unless you define another one in the <code>BROWSER</code> environment
50+
variable.</p>
4951
</dd>
5052
</dl>
5153
</div>

src/etc/man/cargo-doc.1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: cargo-doc
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.10
5-
.\" Date: 2019-09-05
5+
.\" Date: 2019-11-11
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-DOC" "1" "2019-09-05" "\ \&" "\ \&"
10+
.TH "CARGO\-DOC" "1" "2019-11-11" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -41,7 +41,9 @@ is placed in \fBtarget/doc\fP in rustdoc\(cqs usual format.
4141
.sp
4242
\fB\-\-open\fP
4343
.RS 4
44-
Open the docs in a browser after building them.
44+
Open the docs in a browser after building them. This will use your default
45+
browser unless you define another one in the \fBBROWSER\fP environment
46+
variable.
4547
.RE
4648
.sp
4749
\fB\-\-no\-deps\fP

src/etc/man/cargo-help.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-help
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-HELP" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-HELP" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-init.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-init
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-INIT" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-INIT" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-install.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-install
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-07-15
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-10-09
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-INSTALL" "1" "2019-07-15" "\ \&" "\ \&"
10+
.TH "CARGO\-INSTALL" "1" "2019-10-09" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-login.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-login
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-LOGIN" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-LOGIN" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-new.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-new
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-NEW" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-NEW" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-owner.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-owner
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-OWNER" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-OWNER" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-rustdoc.1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: cargo-rustdoc
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.10
5-
.\" Date: 2019-09-05
5+
.\" Date: 2019-11-11
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-RUSTDOC" "1" "2019-09-05" "\ \&" "\ \&"
10+
.TH "CARGO\-RUSTDOC" "1" "2019-11-11" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -58,7 +58,9 @@ option.
5858
.sp
5959
\fB\-\-open\fP
6060
.RS 4
61-
Open the docs in a browser after building them.
61+
Open the docs in a browser after building them. This will use your default
62+
browser unless you define another one in the \fBBROWSER\fP environment
63+
variable.
6264
.RE
6365
.SS "Package Selection"
6466
.sp

src/etc/man/cargo-search.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-search
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-SEARCH" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-SEARCH" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-uninstall.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-uninstall
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-UNINSTALL" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-UNINSTALL" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-version.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-version
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-VERSION" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-VERSION" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo-yank.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: cargo-yank
33
.\" Author: [see the "AUTHOR(S)" section]
4-
.\" Generator: Asciidoctor 2.0.8
5-
.\" Date: 2019-06-07
4+
.\" Generator: Asciidoctor 2.0.10
5+
.\" Date: 2019-06-03
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO\-YANK" "1" "2019-06-07" "\ \&" "\ \&"
10+
.TH "CARGO\-YANK" "1" "2019-06-03" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

src/etc/man/cargo.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: cargo
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.10
5-
.\" Date: 2019-09-05
5+
.\" Date: 2019-10-09
66
.\" Manual: \ \&
77
.\" Source: \ \&
88
.\" Language: English
99
.\"
10-
.TH "CARGO" "1" "2019-09-05" "\ \&" "\ \&"
10+
.TH "CARGO" "1" "2019-10-09" "\ \&" "\ \&"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0

0 commit comments

Comments
 (0)