From 23a2efe7fbf01c8b1418d35d64a4132a80f5870a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 10 Nov 2019 16:57:56 +0000 Subject: [PATCH] Add back support for `BROWSER` envvar in `cargo doc --open`. Fixes #6064. Fixes #5965. --- src/cargo/ops/cargo_doc.rs | 26 ++++++++++++++++++++++-- src/doc/man/cargo-doc.adoc | 4 +++- src/doc/man/cargo-rustdoc.adoc | 4 +++- src/doc/man/generated/cargo-doc.html | 4 +++- src/doc/man/generated/cargo-rustdoc.html | 4 +++- src/etc/man/cargo-doc.1 | 8 +++++--- src/etc/man/cargo-help.1 | 6 +++--- src/etc/man/cargo-init.1 | 6 +++--- src/etc/man/cargo-install.1 | 6 +++--- src/etc/man/cargo-login.1 | 6 +++--- src/etc/man/cargo-new.1 | 6 +++--- src/etc/man/cargo-owner.1 | 6 +++--- src/etc/man/cargo-rustdoc.1 | 8 +++++--- src/etc/man/cargo-search.1 | 6 +++--- src/etc/man/cargo-uninstall.1 | 6 +++--- src/etc/man/cargo-version.1 | 6 +++--- src/etc/man/cargo-yank.1 | 6 +++--- src/etc/man/cargo.1 | 4 ++-- 18 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 6b75e310bef..6fb9f92c78b 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -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)] @@ -77,6 +80,25 @@ 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() { @@ -84,7 +106,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { } } } - } + }; Ok(()) } diff --git a/src/doc/man/cargo-doc.adoc b/src/doc/man/cargo-doc.adoc index 99bfe75ff11..70e37dff913 100644 --- a/src/doc/man/cargo-doc.adoc +++ b/src/doc/man/cargo-doc.adoc @@ -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. diff --git a/src/doc/man/cargo-rustdoc.adoc b/src/doc/man/cargo-rustdoc.adoc index 6d7fea76141..61dfcb413db 100644 --- a/src/doc/man/cargo-rustdoc.adoc +++ b/src/doc/man/cargo-rustdoc.adoc @@ -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 diff --git a/src/doc/man/generated/cargo-doc.html b/src/doc/man/generated/cargo-doc.html index 4c2e774b52d..515cc0e2911 100644 --- a/src/doc/man/generated/cargo-doc.html +++ b/src/doc/man/generated/cargo-doc.html @@ -28,7 +28,9 @@

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
diff --git a/src/doc/man/generated/cargo-rustdoc.html b/src/doc/man/generated/cargo-rustdoc.html index f281504f76f..4c02f893eb4 100644 --- a/src/doc/man/generated/cargo-rustdoc.html +++ b/src/doc/man/generated/cargo-rustdoc.html @@ -45,7 +45,9 @@

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.

diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1 index f1a37c9652f..a0ced6de6bd 100644 --- a/src/etc/man/cargo-doc.1 +++ b/src/etc/man/cargo-doc.1 @@ -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 @@ -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 diff --git a/src/etc/man/cargo-help.1 b/src/etc/man/cargo-help.1 index 17a5a96361f..a69e814840f 100644 --- a/src/etc/man/cargo-help.1 +++ b/src/etc/man/cargo-help.1 @@ -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 diff --git a/src/etc/man/cargo-init.1 b/src/etc/man/cargo-init.1 index 300d76818f2..71137889fb7 100644 --- a/src/etc/man/cargo-init.1 +++ b/src/etc/man/cargo-init.1 @@ -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 diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1 index 4b76a9a8800..358d92109b3 100644 --- a/src/etc/man/cargo-install.1 +++ b/src/etc/man/cargo-install.1 @@ -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 diff --git a/src/etc/man/cargo-login.1 b/src/etc/man/cargo-login.1 index 0da2cd739c2..f3dee23adff 100644 --- a/src/etc/man/cargo-login.1 +++ b/src/etc/man/cargo-login.1 @@ -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 diff --git a/src/etc/man/cargo-new.1 b/src/etc/man/cargo-new.1 index b8266140c5e..a168878248d 100644 --- a/src/etc/man/cargo-new.1 +++ b/src/etc/man/cargo-new.1 @@ -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 diff --git a/src/etc/man/cargo-owner.1 b/src/etc/man/cargo-owner.1 index d0eda6c8454..efd54e39896 100644 --- a/src/etc/man/cargo-owner.1 +++ b/src/etc/man/cargo-owner.1 @@ -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 diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1 index 900f1bb46b9..f606aea6c9d 100644 --- a/src/etc/man/cargo-rustdoc.1 +++ b/src/etc/man/cargo-rustdoc.1 @@ -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 @@ -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 diff --git a/src/etc/man/cargo-search.1 b/src/etc/man/cargo-search.1 index 9672a58f34d..c9233288cc1 100644 --- a/src/etc/man/cargo-search.1 +++ b/src/etc/man/cargo-search.1 @@ -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 diff --git a/src/etc/man/cargo-uninstall.1 b/src/etc/man/cargo-uninstall.1 index 277bc824dd4..0c1ebe202f0 100644 --- a/src/etc/man/cargo-uninstall.1 +++ b/src/etc/man/cargo-uninstall.1 @@ -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 diff --git a/src/etc/man/cargo-version.1 b/src/etc/man/cargo-version.1 index 67639275202..bf61c2bd369 100644 --- a/src/etc/man/cargo-version.1 +++ b/src/etc/man/cargo-version.1 @@ -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 diff --git a/src/etc/man/cargo-yank.1 b/src/etc/man/cargo-yank.1 index 591d92d2203..4a613460782 100644 --- a/src/etc/man/cargo-yank.1 +++ b/src/etc/man/cargo-yank.1 @@ -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 diff --git a/src/etc/man/cargo.1 b/src/etc/man/cargo.1 index 05df60f81a6..2c77e64dfab 100644 --- a/src/etc/man/cargo.1 +++ b/src/etc/man/cargo.1 @@ -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