@@ -4,15 +4,12 @@ use crate::core::shell::Verbosity;
44use crate :: ops;
55use crate :: util;
66use crate :: util:: CargoResult ;
7- use crate :: util:: context:: { GlobalContext , PathAndArgs } ;
87
98use anyhow:: { Error , bail} ;
109use cargo_util:: ProcessBuilder ;
1110
1211use std:: ffi:: OsString ;
13- use std:: path:: Path ;
1412use std:: path:: PathBuf ;
15- use std:: process:: Command ;
1613use std:: str:: FromStr ;
1714
1815/// Format of rustdoc [`--output-format`][1].
@@ -76,7 +73,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
7673 let path = path_by_output_format ( & compilation, & kind, & name, & options. output_format ) ;
7774
7875 if path. exists ( ) {
79- open ( & path, ws. gctx ( ) ) ?;
76+ util :: open :: open ( & path, ws. gctx ( ) ) ?;
8077 }
8178 } else if ws. gctx ( ) . shell ( ) . verbosity ( ) == Verbosity :: Verbose {
8279 for name in & compilation. root_crate_names {
@@ -210,37 +207,3 @@ fn path_by_output_format(
210207 . join ( "index.html" )
211208 }
212209}
213-
214- fn open ( path : & Path , gctx : & GlobalContext ) -> CargoResult < ( ) > {
215- let config_browser = {
216- let cfg: Option < PathAndArgs > = gctx. get ( "doc.browser" ) ?;
217- cfg. map ( |path_args| ( path_args. path . resolve_program ( gctx) , path_args. args ) )
218- } ;
219-
220- let mut shell = gctx. shell ( ) ;
221- let link = shell. err_file_hyperlink ( & path) ;
222- shell. status ( "Opening" , format ! ( "{link}{}{link:#}" , path. display( ) ) ) ?;
223-
224- let browser =
225- config_browser. or_else ( || Some ( ( PathBuf :: from ( gctx. get_env_os ( "BROWSER" ) ?) , Vec :: new ( ) ) ) ) ;
226-
227- match browser {
228- Some ( ( browser, initial_args) ) => {
229- if let Err ( e) = Command :: new ( & browser) . args ( initial_args) . arg ( path) . status ( ) {
230- shell. warn ( format ! (
231- "Couldn't open docs with {}: {}" ,
232- browser. to_string_lossy( ) ,
233- e
234- ) ) ?;
235- }
236- }
237- None => {
238- if let Err ( e) = opener:: open ( & path) {
239- let e = e. into ( ) ;
240- crate :: display_warning_with_error ( "couldn't open docs" , & e, & mut shell) ;
241- }
242- }
243- } ;
244-
245- Ok ( ( ) )
246- }
0 commit comments