|
| 1 | +use crate::core::Workspace; |
1 | 2 | use crate::core::compiler::{Compilation, CompileKind}; |
2 | | -use crate::core::{Shell, Workspace, shell::Verbosity}; |
| 3 | +use crate::core::shell::Verbosity; |
3 | 4 | use crate::ops; |
4 | 5 | use crate::util; |
5 | 6 | use crate::util::CargoResult; |
6 | | -use crate::util::context::{GlobalContext, PathAndArgs}; |
7 | 7 |
|
8 | 8 | use anyhow::{Error, bail}; |
9 | 9 | use cargo_util::ProcessBuilder; |
10 | 10 |
|
11 | 11 | use std::ffi::OsString; |
12 | | -use std::path::Path; |
13 | 12 | use std::path::PathBuf; |
14 | | -use std::process::Command; |
15 | 13 | use std::str::FromStr; |
16 | 14 |
|
17 | 15 | /// Format of rustdoc [`--output-format`][1]. |
@@ -75,14 +73,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { |
75 | 73 | let path = path_by_output_format(&compilation, &kind, &name, &options.output_format); |
76 | 74 |
|
77 | 75 | if path.exists() { |
78 | | - let config_browser = { |
79 | | - let cfg: Option<PathAndArgs> = ws.gctx().get("doc.browser")?; |
80 | | - cfg.map(|path_args| (path_args.path.resolve_program(ws.gctx()), path_args.args)) |
81 | | - }; |
82 | | - let mut shell = ws.gctx().shell(); |
83 | | - let link = shell.err_file_hyperlink(&path); |
84 | | - shell.status("Opening", format!("{link}{}{link:#}", path.display()))?; |
85 | | - open_docs(&path, &mut shell, config_browser, ws.gctx())?; |
| 76 | + util::open::open(&path, ws.gctx())?; |
86 | 77 | } |
87 | 78 | } else if ws.gctx().shell().verbosity() == Verbosity::Verbose { |
88 | 79 | for name in &compilation.root_crate_names { |
@@ -216,33 +207,3 @@ fn path_by_output_format( |
216 | 207 | .join("index.html") |
217 | 208 | } |
218 | 209 | } |
219 | | - |
220 | | -fn open_docs( |
221 | | - path: &Path, |
222 | | - shell: &mut Shell, |
223 | | - config_browser: Option<(PathBuf, Vec<String>)>, |
224 | | - gctx: &GlobalContext, |
225 | | -) -> CargoResult<()> { |
226 | | - let browser = |
227 | | - config_browser.or_else(|| Some((PathBuf::from(gctx.get_env_os("BROWSER")?), Vec::new()))); |
228 | | - |
229 | | - match browser { |
230 | | - Some((browser, initial_args)) => { |
231 | | - if let Err(e) = Command::new(&browser).args(initial_args).arg(path).status() { |
232 | | - shell.warn(format!( |
233 | | - "Couldn't open docs with {}: {}", |
234 | | - browser.to_string_lossy(), |
235 | | - e |
236 | | - ))?; |
237 | | - } |
238 | | - } |
239 | | - None => { |
240 | | - if let Err(e) = opener::open(&path) { |
241 | | - let e = e.into(); |
242 | | - crate::display_warning_with_error("couldn't open docs", &e, shell); |
243 | | - } |
244 | | - } |
245 | | - }; |
246 | | - |
247 | | - Ok(()) |
248 | | -} |
0 commit comments