Add back support for BROWSER envvar in cargo doc --open.

Fixes #6064.
Fixes #5965.
This commit is contained in:
Diogo Sousa 2019-11-10 16:57:56 +00:00
parent 0c0f9aeccf
commit 23a2efe7fb
18 changed files with 78 additions and 44 deletions

View File

@ -1,10 +1,13 @@
use crate::core::resolver::ResolveOpts; use crate::core::resolver::ResolveOpts;
use crate::core::Workspace; use crate::core::{Shell, Workspace};
use crate::ops; use crate::ops;
use crate::util::CargoResult; use crate::util::CargoResult;
use failure::Fail; use failure::Fail;
use opener; use opener;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error;
use std::path::Path;
use std::process::Command;
/// Strongly typed options for the `cargo doc` command. /// Strongly typed options for the `cargo doc` command.
#[derive(Debug)] #[derive(Debug)]
@ -77,6 +80,25 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
if path.exists() { if path.exists() {
let mut shell = options.compile_opts.config.shell(); let mut shell = options.compile_opts.config.shell();
shell.status("Opening", path.display())?; 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) { if let Err(e) = opener::open(&path) {
shell.warn(format!("Couldn't open docs: {}", e))?; shell.warn(format!("Couldn't open docs: {}", e))?;
for cause in (&e as &dyn Fail).iter_chain() { for cause in (&e as &dyn Fail).iter_chain() {
@ -84,7 +106,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
} }
} }
} }
} };
Ok(()) Ok(())
} }

View File

@ -21,7 +21,9 @@ is placed in `target/doc` in rustdoc's usual format.
=== Documentation Options === Documentation Options
*--open*:: *--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*:: *--no-deps*::
Do not build documentation for dependencies. Do not build documentation for dependencies.

View File

@ -33,7 +33,9 @@ option.
=== Documentation Options === Documentation Options
*--open*:: *--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 === Package Selection

View File

@ -28,7 +28,9 @@ is placed in <code>target/doc</code> in rustdoc&#8217;s usual format.</p>
<dl> <dl>
<dt class="hdlist1"><strong>--open</strong></dt> <dt class="hdlist1"><strong>--open</strong></dt>
<dd> <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> </dd>
<dt class="hdlist1"><strong>--no-deps</strong></dt> <dt class="hdlist1"><strong>--no-deps</strong></dt>
<dd> <dd>

View File

@ -45,7 +45,9 @@ option.</p>
<dl> <dl>
<dt class="hdlist1"><strong>--open</strong></dt> <dt class="hdlist1"><strong>--open</strong></dt>
<dd> <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> </dd>
</dl> </dl>
</div> </div>

View File

@ -2,12 +2,12 @@
.\" Title: cargo-doc .\" Title: cargo-doc
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05 .\" Date: 2019-11-11
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-DOC" "1" "2019-09-05" "\ \&" "\ \&" .TH "CARGO\-DOC" "1" "2019-11-11" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0
@ -41,7 +41,9 @@ is placed in \fBtarget/doc\fP in rustdoc\(cqs usual format.
.sp .sp
\fB\-\-open\fP \fB\-\-open\fP
.RS 4 .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 .RE
.sp .sp
\fB\-\-no\-deps\fP \fB\-\-no\-deps\fP

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-help .\" Title: cargo-help
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-HELP" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-HELP" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-init .\" Title: cargo-init
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-INIT" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-INIT" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-install .\" Title: cargo-install
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-07-15 .\" Date: 2019-10-09
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-INSTALL" "1" "2019-07-15" "\ \&" "\ \&" .TH "CARGO\-INSTALL" "1" "2019-10-09" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-login .\" Title: cargo-login
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-LOGIN" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-LOGIN" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-new .\" Title: cargo-new
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-NEW" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-NEW" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-owner .\" Title: cargo-owner
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-OWNER" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-OWNER" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -2,12 +2,12 @@
.\" Title: cargo-rustdoc .\" Title: cargo-rustdoc
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05 .\" Date: 2019-11-11
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-RUSTDOC" "1" "2019-09-05" "\ \&" "\ \&" .TH "CARGO\-RUSTDOC" "1" "2019-11-11" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0
@ -58,7 +58,9 @@ option.
.sp .sp
\fB\-\-open\fP \fB\-\-open\fP
.RS 4 .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 .RE
.SS "Package Selection" .SS "Package Selection"
.sp .sp

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-search .\" Title: cargo-search
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-SEARCH" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-SEARCH" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-uninstall .\" Title: cargo-uninstall
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-UNINSTALL" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-UNINSTALL" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-version .\" Title: cargo-version
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-VERSION" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-VERSION" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -1,13 +1,13 @@
'\" t '\" t
.\" Title: cargo-yank .\" Title: cargo-yank
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.8 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-06-07 .\" Date: 2019-06-03
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO\-YANK" "1" "2019-06-07" "\ \&" "\ \&" .TH "CARGO\-YANK" "1" "2019-06-03" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0

View File

@ -2,12 +2,12 @@
.\" Title: cargo .\" Title: cargo
.\" Author: [see the "AUTHOR(S)" section] .\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10 .\" Generator: Asciidoctor 2.0.10
.\" Date: 2019-09-05 .\" Date: 2019-10-09
.\" Manual: \ \& .\" Manual: \ \&
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "CARGO" "1" "2019-09-05" "\ \&" "\ \&" .TH "CARGO" "1" "2019-10-09" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq .ie \n(.g .ds Aq \(aq
.el .ds Aq ' .el .ds Aq '
.ss \n[.ss] 0 .ss \n[.ss] 0