1- use crate :: core:: compiler:: RustcTargetData ;
21use crate :: core:: resolver:: HasDevUnits ;
32use crate :: core:: { Shell , Workspace } ;
43use crate :: ops;
54use crate :: util:: CargoResult ;
5+ use crate :: { core:: compiler:: RustcTargetData , util:: config:: PathAndArgs } ;
66use serde:: Deserialize ;
7- use std:: collections:: HashMap ;
8- use std:: ffi:: OsString ;
97use std:: path:: Path ;
108use std:: process:: Command ;
9+ use std:: { collections:: HashMap , path:: PathBuf } ;
1110
1211/// Strongly typed options for the `cargo doc` command.
1312#[ derive( Debug ) ]
@@ -22,7 +21,7 @@ pub struct DocOptions {
2221struct CargoDocConfig {
2322 /// Browser to use to open docs. If this is unset, the value of the environment variable
2423 /// `BROWSER` will be used.
25- browser : Option < String > ,
24+ browser : Option < PathAndArgs > ,
2625}
2726
2827/// Main method for `cargo doc`.
@@ -92,19 +91,31 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
9291 if path. exists ( ) {
9392 let mut shell = ws. config ( ) . shell ( ) ;
9493 shell. status ( "Opening" , path. display ( ) ) ?;
95- let cfg = ws. config ( ) . get :: < CargoDocConfig > ( "cargo-doc" ) ?;
96- open_docs ( & path, & mut shell, cfg. browser . map ( |v| v. into ( ) ) ) ?;
94+ let cfg = ws. config ( ) . get :: < CargoDocConfig > ( "doc" ) ?;
95+ open_docs (
96+ & path,
97+ & mut shell,
98+ cfg. browser . map ( |path_args| {
99+ ( path_args. path . resolve_program ( & ws. config ( ) ) , path_args. args )
100+ } ) ,
101+ ) ?;
97102 }
98103 }
99104
100105 Ok ( ( ) )
101106}
102107
103- fn open_docs ( path : & Path , shell : & mut Shell , config_browser : Option < OsString > ) -> CargoResult < ( ) > {
104- let browser = config_browser. or_else ( || std:: env:: var_os ( "BROWSER" ) ) ;
108+ fn open_docs (
109+ path : & Path ,
110+ shell : & mut Shell ,
111+ config_browser : Option < ( PathBuf , Vec < String > ) > ,
112+ ) -> CargoResult < ( ) > {
113+ let browser =
114+ config_browser. or_else ( || Some ( ( PathBuf :: from ( std:: env:: var_os ( "BROWSER" ) ?) , Vec :: new ( ) ) ) ) ;
115+
105116 match browser {
106- Some ( browser) => {
107- if let Err ( e) = Command :: new ( & browser) . arg ( path) . status ( ) {
117+ Some ( ( browser, initial_args ) ) => {
118+ if let Err ( e) = Command :: new ( & browser) . args ( initial_args ) . arg ( path) . status ( ) {
108119 shell. warn ( format ! (
109120 "Couldn't open docs with {}: {}" ,
110121 browser. to_string_lossy( ) ,
0 commit comments