1
- use crate :: core:: compiler:: RustcTargetData ;
2
1
use crate :: core:: resolver:: HasDevUnits ;
3
2
use crate :: core:: { Shell , Workspace } ;
4
3
use crate :: ops;
5
4
use crate :: util:: CargoResult ;
5
+ use crate :: { core:: compiler:: RustcTargetData , util:: config:: PathAndArgs } ;
6
6
use serde:: Deserialize ;
7
- use std:: collections:: HashMap ;
8
- use std:: ffi:: OsString ;
9
7
use std:: path:: Path ;
10
8
use std:: process:: Command ;
9
+ use std:: { collections:: HashMap , path:: PathBuf } ;
11
10
12
11
/// Strongly typed options for the `cargo doc` command.
13
12
#[ derive( Debug ) ]
@@ -22,7 +21,7 @@ pub struct DocOptions {
22
21
struct CargoDocConfig {
23
22
/// Browser to use to open docs. If this is unset, the value of the environment variable
24
23
/// `BROWSER` will be used.
25
- browser : Option < String > ,
24
+ browser : Option < PathAndArgs > ,
26
25
}
27
26
28
27
/// Main method for `cargo doc`.
@@ -92,19 +91,31 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
92
91
if path. exists ( ) {
93
92
let mut shell = ws. config ( ) . shell ( ) ;
94
93
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
+ ) ?;
97
102
}
98
103
}
99
104
100
105
Ok ( ( ) )
101
106
}
102
107
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
+
105
116
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 ( ) {
108
119
shell. warn ( format ! (
109
120
"Couldn't open docs with {}: {}" ,
110
121
browser. to_string_lossy( ) ,
0 commit comments